gpt4 book ai didi

mysql - 子查询总是返回单条记录

转载 作者:行者123 更新时间:2023-11-29 01:38:03 30 4
gpt4 key购买 nike

我尝试合并查询 1 是查询 2 的子查询到 3。但它总是返回单个记录。以下是我的查询,

1.SELECT REPLACE(LEFT(friend_id, LENGTH(friend_id)-2),'["','') AS friend_id FROM `friends_list` WHERE login_userid=90 

Output :
friend_id
32,44

2.SELECT id, CONCAT(firstname," ",lastname) AS username FROM register WHERE id IN(32,44)

Output :
id username
32 Suresh M
44 Senthil Kumar

示例代码,

3.SELECT t1.id, CONCAT(t1.firstname," ",t1.lastname) AS username 
FROM register AS t1
INNER JOIN friends_list AS t2 ON t1.id=t2.login_userid
WHERE t1.id IN( SELECT REPLACE(LEFT(friend_id, LENGTH(friend_id)-2),'["','') AS friend_id FROM `friends_list` WHERE login_userid=90 )

Output :
id username
32 Suresh M

我想要结果,

id  username    
32 Suresh M
44 Senthil Kumar

请更正我的错误查询(第 3 次)。

最佳答案

只需删除您的内部连接条件

SELECT t1.id, CONCAT(t1.firstname," ",t1.lastname) AS username 
FROM register AS t1
WHERE t1.id IN( SELECT REPLACE(LEFT(friend_id, LENGTH(friend_id)-2),'["','') AS friend_id FROM `friends_list` WHERE login_userid=90 )

关于mysql - 子查询总是返回单条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34217040/

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