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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LEFT JOIN with field in where clause 1

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
So I have a left join going on, and my where clause has a field does not equal value on one of the fields in the table which is left joined.

So the problem is, if the left join returns no rows, then the where clause is automatically failing (even though it doesn't equal) so the row doesn't show up... so basically what I want is, if LEFT JOIN fails on this table or the where clause evaluates to true, then do it.

Perhaps an example will help
Table a: id, name
Table b: id, sex

SELECT a.id, a.name, b.sex
FROM a
LEFT JOIN ON a.id=b.id
WHERE a.id > 5
AND b.sex != 'male'

So I want everyone I can't prove is male, that is both people who are female, and people who have no entry in the b table.
 
SELECT a.id, a.name, b.sex
FROM a
LEFT JOIN ON a.id=b.id
AND b.sex <> 'male'
WHERE a.id > 5

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top