[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

inner/outer join question




Slightly off topic but at least this query is being used in a java app.

I have three tables,  A   B  and AB.
I have two values which are PK in A B respectively,  Aid, Bid
I have a value from another table Cid
Cid is also in A
Aid Bid and Cid are in AB and are the PK together
Bid is a specified value referred to below as SP.Bid
Cid is a specified value referred to below as SP.Cid

I would like to get all records in A that meet the following criteria.  

records not present in AB whose AB.Cid=SP.Cid
combined with(UNION)
records present in AB whose AB.Aid=A.Aid and AB.Cid=SP.Cid and AB.Bid<>SP.Bid


I am having problems with the syntax, I can't seem to get it to come out right.

I know people have done these sort of joins before but I am more of a dabbler in SQL.  So, any help would be appreciated.

Thanks,

-Jason