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

UNION outer joins

Status
Not open for further replies.

BiggerBrother

Technical User
Sep 9, 2003
702
GB
I know this returns all the records in a field, and that it is the longest way to return these records, but it is the product of 2 built statements, so there is reason behind the madness.
(

SELECT DISTINCT contact. *
FROM contact
LEFT OUTER JOIN location ON ind_id = loc_indid
WHERE loc_id IS NULL
)
UNION (

SELECT DISTINCT contact. *
FROM contact
LEFT OUTER JOIN location ON ind_id = loc_indid
WHERE loc_id IS NOT NULL
)

Bascially, the first statement selects all entries in contact which do not appear in location, and the second does the reverse.

At the moment, the two statements work independantly, but once I add the UNION statemnet, it returns an error in the string after UNION. Where am I going wrong??

BB
 
Helpfully, it's just the standard:

You have an error in your SQL syntax near '( SELECT DISTINCT contact. * FROM contact LEFT OUTER JOIN location ON ind_i' at line 1

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top