MySQL multiple SELECT statements

MySQLsql

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 = comments.postid)

However, it doesn't work… help!

Best Answer

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