我有两张桌子。我只想得到roomsusersrooms.room_id。我可以通过下面的sql得到所有用户的结果。。。

select rooms.room_id,
       rooms.user_id,
       users.user_name
  from rooms
LEFT JOIN users ON rooms.user_id = users.user_id

当我想这样过滤用户id=1的结果时。。。我搞错了。
select rooms.room_id,
       rooms.user_id,
       users.user_name
  from rooms where rooms.user_id = 1
LEFT JOIN users ON rooms.user_id = users.user_id

我该怎么办?

最佳答案

将查询编写为:

select rooms.room_id,
       rooms.user_id,
       users.user_name
  from rooms
LEFT JOIN users ON rooms.user_id = users.user_id
WHERE roows.user_id = 1

关于sql - 帮助MySQL查询?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2706460/

10-10 19:21