Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Two conditions in sql query

Author  Topic 

Starlet_GT
Yak Posting Veteran

81 Posts

Posted - 2009-08-19 : 01:33:10
Guys, I need to check two conditions while running a query.

Suppose I have two tables

Table A--------------Table B
Col1---Col2----------Col1---Col2
A-------1--------------A-----2
B-------5--------------B-----5
C-------7--------------C-----7
D-------1--------------E-----3
F-------8
G-------1
I want to select all data from Table A where two colums are different and all values of Table A which did not exists in Table B

Results should be like this:
Col1---Col2
A-------1
D-------1
F-------8
G-------1

how to do it ... Thanks in advance

Best regards,
MIZ

Mangal Pardeshi
Posting Yak Master

110 Posts

Posted - 2009-08-19 : 01:35:24
[code]

SELECT col1, col2
FROM TableA
EXCEPT
SELECT col1, col2
FROM TableB

[/code]

Mangal Pardeshi
http://mangalpardeshi.blogspot.com
Go to Top of Page

Starlet_GT
Yak Posting Veteran

81 Posts

Posted - 2009-08-19 : 01:44:09
Thank you ... it's work :)
Go to Top of Page
   

- Advertisement -