sql - check if the column value exists in subquery -
i have 3 tables product category , productcategory.
product table:
productid productname 1 p1 2 p2 3 p3 category table:
categoryid categoryname 1 c1 2 c2 3 c3 productcategory:
productid categoryid 1 1 1 2 1 3 2 3 3 1 3 2 i need query returns products fall under more 1 categories. based on table data above result be:
productid productname 1 p1 3 p3 so wrote query fetch productid's have more 1 categoryid's below:
select productid,count(categoryid) productcategory group productid having count(categoryid)>1) but when try display product details using below query error:
select * product productid in ( select productid,count(categoryid) productcategory group productid having count(categoryid)>1)) is query wrong? how required product details fall in more 1 categories?
remove count() in subquery. result of subquery when used on in clause must have 1 returned column.
select * product productid in ( select productid productcategory group productid having count(categoryid) > 1 ) or using join
select a.* product inner join ( select productid productcategory group productid having count(categoryid) > 1 ) b on a.productid = b.productid
Comments
Post a Comment