Ok, so I have a table that contains optionID, optionName. Its called user_options. I have a second table that contains userID, optionID. Its called user_selected_options.
Options in user_options are stored for a user in user_selected_options, which is fine. Now, when editing a user, I just want to show the options from user_options which are not selected for that user in user_selected_options as select boxes. How can I do this?
I hope this question make sense. Please let me know if it is unclear and I will explain further.
Thanks for any tips.
Here is one method using not exists
:
select uo.*
from user_options uo
where not exists (select 1
from user_selected_options uso
where uso.optionId = uo.option_id and uso.userId = $userId
);
For best performance, create an index on user_selected_options(option_id, userId)
.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments