Skip to content
Advertisement

check if the column value exists in subquery

i have 3 tables Product Category and ProductCategory.

Product table:

Category table:

ProductCategory:

I need a query which returns products which fall under more than 1 categories. Based on the table data above the result would be:

So i wrote a query to fetch all the ProductID’s which have more than one CategoryID’s as below:

But when i try to display product details using the below query i get an error:

Is my query wrong? How do i get the required product details which fall in more than one categories?

Advertisement

Answer

Remove the COUNT() in the subquery. The result of the subquery when used on IN clause must have only one returned column.

or by using JOIN

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement