I need to use several SELECT statements in one statement. I've checked out some other questions and figured that this should work:
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 = comm开发者_如何学编程ents.postid)
However, it doesn't work... help!
Assuming you want a list of all users that have either posted or left a comment, UNION ALL is what you want (I changed the FROM/WHERE clauses accordingly):
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
精彩评论