SELECT status.*,
users.username
FROM status,
users
WHERE status.user_id = users.id
UNION
SELECT comments.user_id,
comments.commente,
comments.date_of_creation,
users.username
FROM comments,
users
WHERE comments.status_id = (SELECT status.*
FROM status
WHERE id = comments.statu_id) &&
comments.user_id = users.id
ORDER BY status.id DESC;
答案 0 :(得分:1)
我注意到user_id对所有表都是通用的。你只需要一些连接:
SELECT s.*,
c.user_id,
c.commente,
c.date_of_creation,
u.username
FROM users u
inner join status s on s.user_id = u.user_id
inner join comments c on c.user_id = u.user_id
ORDER BY s.id DESC;