I'm having a hard time to use a MySQL query.
If I do the following:
SELECT ads.id_ad
FROM tab_ads ads, tab_orders orders
WHERE (ads.id_user = 111 AND ads.id_ad = orders.id_ad)
It gives me the correct answer, which is: "show me the ads belonging to user 111 that have been sold"
What I want is to remove all ads, except the ads that have been sold.
So I change the equal to not equal in the where criteria:
SELECT ads.id_ad
FROM tab_ads ads, tab_orders orders
WHERE (ads.id_user = 111 AND ads.id_ad != orders.id_ad)
And it gives me trash results.
Ex: I have three tables:
tab_ads
id_ad - title - etc.
01 - title1
02 - title2
03 - title3
tab_orders
id_order - id_ad - amount - etc.
XX - 01 - $10
tab_users
id_user - name - etc.
110 - Dr. Jivago - etc.
111 - Sherlock - etc.
I need to remove all ads from 111 (Sherlock) where there's no sell. So I need to remove ad 02 - title2 and 03 - title3 because ad 01 - title1 has been sold and I need to keep it for future consultation.