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

Nulls within a join condition

Status
Not open for further replies.

oraclejunior

Technical User
Jul 8, 2003
111
GB
I have a select query with a where condition but a number of the conditions may contain Nulls which results in nothing being returned by the query. How do I get around this eg

From CellTable, ElementTable A1, ElementTable A2

WHERE CellTable.Elememt1ID = A1.ElementID
CellTable.Element2ID = A2.ElementID

But the thing is that Element2ID may be null ie the record does not have an Element2ID assigned to it.

This is causing the query to return nothing. What is the work around?







 
WHERE (CellTable.Element1ID = A1.ElementID OR CellTable.Element1ID Is Null) AND (CellTable.Element2ID = A2.ElementID OR CellTable.Element2ID Is Null)
 
As a further point

From CellTable, ElementTable A1, ElementTable A2

WHERE CellTable.Elememt1ID = A1.ElementID
CellTable.Element2ID = A2.ElementID

goes all the way to CellTable.Element9ID, and the problem with the above solution is it will select every record.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top