像这样的东西会起作用,但这不是一个非常优雅的解决方案。
SELECT q.post_id, q.post_user_id, q.post, q.post_date, q.post_visible,
q.user_id, q.username, q.user_email, q.user_first, q.user_last
FROM (
SELECT post_id, user_id AS post_user_id, post, post_date, visible AS post_visible,
0 AS user_id, "" AS username, "" AS user_email, "" AS user_first, "" AS user_last
FROM posts
WHERE post like ?
UNION
SELECT 0 AS post_id, "" AS post_user_id, "" AS post, "" AS post_date, 0 AS post_visible,
userid AS user_id, username, email AS user_email, firstname AS user_first, lastname AS user_last
FROM users
WHERE username like ?
OR email like ?
) q
ORDER BY q.post_id DESC