SQL Selecting from one table OR another then joining the two

Posted by Cyprus106 on Stack Overflow See other posts from Stack Overflow or by Cyprus106
Published on 2010-04-21T19:11:56Z Indexed on 2010/04/21 19:13 UTC
Read the original article Hit count: 194

Filed under:
|
|
|

So this is interesting, and apparently beyond my SQL skillset.

I need to select a particular record where an ID="0003" (or whatever) from either table1 or table2 if table1 doesn't have that record. Then I need to join table1 and table2 on a mutual field they both have (field name is Product_ID)

I was playing with all sorts of variations of the following, (no, it doesn't work) but after 2 days of groping through the internet and a big SQL book I still can't figure anything out.

SELECT ProductStock.Product_ID AS PSID, 
Products.ID AS PID, 
ProductStock.*,
Products.*
FROM ProductStock, Products LEFT JOIN (Products AS Pr) ON Pr.ID=ProductStock.Product_ID WHERE (ProductStock.ID="6003" OR Products.ID="6003")

© Stack Overflow or respective owner

Related posts about sql

Related posts about query