Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INNER JOIN on same table 1

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
IE
Given table tblA
A varchar(100), B int, C int

A B C
100 | 1 | 1
100 | NULL | 2
100 | NULL | 3
200 | 2 | 2
300 | 3 | 1
300 | NULL | 2
400 | 4 | 1
400 | NULL | 2
400 | NULL | 3
500 | 5 | NULL
500 | 6 | NULL

How do I return all records where C IS NOT NULL but with it's corresponding B value for the A record. So for example

A B C
100 | 1 | 1
100 | 1 | 2
100 | 1 | 3
200 | 2 | 2
300 | 3 | 1
300 | 3 | 2
400 | 4 | 1
400 | 4 | 2
400 | 4 | 3

Thanks
 
SELECT A.A,B.B,A.C
FROM yourTable A INNER JOIN yourTable B ON A.A=B.A
WHERE A.C IS NOT NULL AND B.B IS NOT NULL

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top