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

Criteria for non-existent data??

Status
Not open for further replies.

jchastai

Programmer
Oct 11, 2001
31
US

I have a query that does a left join between two tables (i.e. there may or may not be records in the second table, but I want all records from the first table).

Now I need to apply a certain criteria to the records that come from the second table ... but what if there are no records?

How should I do this?

SELECT table1.field, table2.field
FROM table1 LEFT JOIN table2 ON table1.field = table2.field
WHERE table2.field GT 1

??? This throws an error when there are no results returned from table 2.

Thanks
Jeff
 
Add a test for Null.

SELECT table1.field, table2.field
FROM table1 LEFT JOIN table2
ON table1.field = table2.field
WHERE table2.field GT 1
OR table2.field Is Null Terry L. Broadbent - Salt Lake City, UT
Home of the 2002 Winter Olympics (Feb 8-24)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top