l'll explain the use-case simply with following scenario. Basically,i want to find all the pts/s from pts_table which contains all the orders of the pl001
pl_table
========
pl_id | order_id
pl001 order001
pts_table
=========
pts_id | order_id
pts001 order001
pts002 order001
pts002 order002
Here is the query im trying,
SELECT pts_id
FROM pts_table
WHERE pts_table.order_id IN (SELECT DISTINCT(plt.order_id) FROM pl_table
as plt where plt.pl_id=pl001)// to check element equality.
GROUP BY pts_id
HAVING COUNT(DISTINCT pts_table.order_id) = (SELECT COUNT(plt2.order_id)
FROM pl_table as plt2 where plt.pl_id=pl001)//to check size equality.
But unfortunately this query returns both pts001 and pts002 which is not correct.it should only return pts001 as the result!. as i figured out this is due to incorrect grouping part.
Can anyone suggest me how to correct this or any other better way? Any help is greatly appreciated.