gpt4 book ai didi

php - Mysql 多表查询

转载 作者:行者123 更新时间:2023-11-29 11:32:05 25 4
gpt4 key购买 nike

好的,我有一个包含 optionID、optionName 的表。它称为 user_options。我有第二个表,其中包含 userID、optionID。它称为 user_selected_options。

user_options 中的选项存储在 user_selected_options 中,这很好。现在,在编辑用户时,我只想将 user_options 中未在 user_selected_options 中为该用户选择的选项显示为选择框。我怎样才能做到这一点?

我希望这个问题有意义。如果不清楚,请告诉我,我会进一步解释。

感谢您的任何提示。

最佳答案

这是一种使用不存在的方法:

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
);

为了获得最佳性能,请在 user_selected_options(option_id, userId) 上创建索引。

关于php - Mysql 多表查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37239132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com