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 2000 Forums
 SQL Server Development (2000)
 How tho join this ? (<>)

Author  Topic 

Incognito
Starting Member

49 Posts

Posted - 2003-05-19 : 09:36:25
Hello,

Who can help me out ?

The situation is like this: Two tables A and B with some records.

Table A Table B
XID - YID---- QID - PID

17 5---- 17 5
17 7---- 17 7
17 8---- 20 1
20 1---- 35 2
20 2---- 35 3
35 2
35 3

I want to show the records which not exist in Table B.
For example XID 17 and YID 8 must be shown with the query. (I tried Select * From TableA, TableB Where XID = QID and YID <> PID but it did not work :((()

Who can give me some tips with this ?

Thnx a lot,

G



Edited by - Incognito on 05/19/2003 09:37:37

bba
Starting Member

3 Posts

Posted - 2003-05-19 : 10:04:11
Please try the following. I have also copied the results of the query. Hope this helps.

create table TableA
(
XID int,
YID int
)

create table TableB
(
QID int,
PID int
)



insert into TableA values (17, 5)
insert into TableB values (17, 5)
insert into TableA values (17, 7)
insert into TableB values (17, 7)
insert into TableA values (17, 8)
insert into TableB values (20, 1 )
insert into TableA values (20, 1)
insert into TableB values (35, 2 )
insert into TableA values (20, 2)
insert into TableB values (35, 3 )
insert into TableA values (35, 2)
insert into TableA values (35, 3)

Select *
From TableA
Where not exists
(select * from TableB
where (XID = QID)
and (YID = PID)
)

Result:
XID YID
----------- -----------
17 8
20 2


Go to Top of Page

Incognito
Starting Member

49 Posts

Posted - 2003-05-19 : 10:13:04
Thnx a lot.
This works perfect !

Go to Top of Page
   

- Advertisement -