我需要在一个语句中使用几个SELECT语句。我已经检查了一些其他问题,并认为这应该有效:
SELECT (SELECT users.fname, users.lname, posts.post
FROM users, posts, comments
WHERE users.userid = posts.userid)
(SELECT users.fname, users.lname, comments.text
FROM users
WHERE comments.userid = users.userid
AND posts.postid = comments.postid)
然而,它不起作用......帮助!
答案 0 :(得分:5)
假设您想要一个已发布或留下评论的所有用户的列表,UNION ALL就是您想要的(我相应地更改了FROM / WHERE子句):
SELECT users.fname, users.lname, posts.post
FROM users, posts
WHERE users.userid = posts.userid
UNION ALL
SELECT users.fname, users.lname, comments.text
FROM users, comments
WHERE comments.userid = users.userid