Reputation: 65
I have two table suppose products
and auto_assign_prod_list
. I want to populate a dropdown list with the id of products table that are not present in auto_assign_prod_list table.
Suppose, product table contain
Id
------
1
2
3
4
5
auto_assign_prod_list table contain
Id
-----
1
5
So, my result set will be
2
3
4
How is it possible using MySQL and PHP ?
Upvotes: 0
Views: 109
Reputation: 18737
Try this:
SELECT Id FROM product
WHERE Id NOT IN (SELECT Id FROM auto_assign_prod_list)
It will select the ids from product
table which are not in auto_assign_prod_list
table.
Result:
Id
------
2
3
4
See result in SQL Fiddle.
Upvotes: 1
Reputation: 204746
use a left join
select p.id
from products p
left join auto_assign_prod_list a on a.id = p.id
where a.id is null
See this great explanation of joins
Upvotes: 0