1
tbl_pack_service;
+-------+---------+------------+
| ps_id | pack_id | service_id |
+-------+---------+------------+
|     1 |       1 |          1 |
|     2 |       1 |          2 |
|     3 |       2 |          1 |
|     4 |       2 |          2 |
|     5 |       2 |          3 |
|     6 |       2 |          4 |
|     7 |       2 |          5 |
|     8 |       3 |          1 |
|     9 |       3 |          2 |
|    10 |       3 |          3 |
|    11 |       3 |          4 |
+-------+---------+------------+

ps_id is primary key i am tying to make dynamic select list in php i want a mysql query that can give service id which do not match with particular pack_id

like i have service_id 1,2,3,4,5 when i should select pack_id=1 then 3,4,5 should be displayed and when i should select pack_id=2 then nothing should be displayed as it has all the 5 services. thanks..

1 Answer 1

3

There are a few ways to handle this. The easiest is with a NOT IN subquery:

SELECT DISTINCT service_id
FROM 
  tbl_pack_service
WHERE service_id NOT IN (SELECT service_id FROM tbl_pack_service WHERE pack_id = 1)
Sign up to request clarification or add additional context in comments.

1 Comment

My friend did somebody told you that you are genius.. this works flawlessly like magic..thanks alot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.