gpt4 book ai didi

mysql - 将子查询转换为连接查询

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

对于这个查询:

SELECT `user_id`, `user_name` FROM users WHERE `user_id` IN (SELECT user_one, user_two FROM friends WHERE user_one='$my_id' OR user_two = '$my_id')

我收到此错误消息:

Cardinality violation: 1241 Operand should contain 1 column(s)

是否可以在连接中使用 2 列而不是子查询?如果是,怎么做?

最佳答案

为什么不使用这样的联合:

SELECT `user_id`, `user_name` 
FROM users
WHERE `user_id` IN (SELECT user_one FROM friends
where user_one = '$my_id'
UNION
SELECT user_two FROM friends
where user_two = '$my_id')

关于mysql - 将子查询转换为连接查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28703050/

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