hi,
i have two entities products and categories. both have many-to-many relation. how can i get the products that are not related with the categories. i mean the ones which not not mapped in junction table.
thank you!
daniyal nawaz
hi,
i have two entities products and categories. both have many-to-many relation. how can i get the products that are not related with the categories. i mean the ones which not not mapped in junction table.
thank you!
daniyal nawaz
SELECT * FROM products WHERE product_id NOT IN (SELECT DISTINCT product_id FROM junction_table)
Try this :
select products .*,junction_table.product_id from products
left outer join junction_table
on junction_table.product_id=products .product_id
having junction_table.product_id is null
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.