gpt4 book ai didi

php - MYSQL|来自两个表的请求2

转载 作者:行者123 更新时间:2023-11-30 01:25:57 27 4
gpt4 key购买 nike

我有 2 个 Mysql 表:

A(用户表):

id用户名房间

1    User1    1 
2 User2 1
3 User3 1

B(被阻止的用户):

id   username
1 User3

我的请求在这里(我想获取 User1 和 User2,因为 User3 处于阻塞状态):

SELECT A.id, A.username FROM `table1` A, `table2` B 
WHERE A.roomid = 1 AND A.username != B.username

但这是错误的请求。谢谢!

最佳答案

您需要加入两个表A和B,例如

SELECT A.id, A.username FROM `table1` A
JOIN `table2` as B ON `table1`.id = `table2`.id
WHERE A.room = 1 AND A.username != B.username

或者您的列名称是 room 而不是 roomid

SELECT A.id, A.username FROM `table1` A, `table2` B 
WHERE A.room = 1 AND A.username != B.username

关于php - MYSQL|来自两个表的请求2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17986219/

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