
January 29th, 2013, 01:51 PM
|
|
Me
|
|
Join Date: Apr 2007
Location: San Diego, CA
Posts: 2,267
 
Time spent in forums: 2 Weeks 1 Day 6 h 30 m 38 sec
Reputation Power: 9
|
|
if you want to find where id exists in both tables you can do an inner join query. the result will hav eonly rows where the id exists in both tables. to find where an id exists in only 1 table, you can do a left join where the second table join key is null. here are some examples:
given the structure you specified using "temp" for the temp table and "permanent" for the permanent table name. you will of course need to change the names.
exists in both:
Code:
SELECT product_id
FROM permanent
INNER JOIN temp
ON permanent.product_id=temp.product_id
exists only in permanent, not in temp
Code:
SELECT product_id
FROM permanent
LEFT JOIN temp
ON perment.product_id=temp.product_id
WHERE
temp.product_id IS NULL
reverse above, only in temp, not in permanent
Code:
SELECT product_id
FROM temp
LEFT JOIN permanent
ON perment.product_id=temp.product_id
WHERE
permanent.product_id IS NULL
|