Questions | Login

Top / PHP / MySQL

MySQL query? Someone help me?

demo 18 Dec 2008 08:25am
I have two tables,
Table1, Table2.
Table1 contains products.(product_id, product_name)
And Table2 contains all the products that are ordered.(order_id, product_id, product_name)
Suppose if I delete a product, corresponding record will be deleted from Table1.

Now if I need to know what are the product_id's in Table2 that are deleted or Not in Table1.

Please give me query
Query given by 'CatNip' gives a number of Indentical records. Any other info please..

Answers

demo 18 Dec 2008 08:50am
Select product_id From Table2
Where product_id not in (Select product_id From Table1)
demo 18 Dec 2008 09:52am
SELECT DISTINCT
Table2.Product

FROM
Table2

WHERE
Table2.ProductID NOT IN (SELECT Table1.ProductID FROM Table1)

Related

Submit Answer

You must be logged in to post an answer. Please Login or Register.

Powered by phpMyAnswers.