我有 3 个类似的表,有 1 个不同的列
id | user_id | post_id | other_id | favorite(tinyint) | date
id | user_id | post_id | other_id | like(tinyint) | date
id | user_id | post_id | other_id | comment(tinyint) | date
有没有办法返回所有组合,其中 user_id = 1 并按日期排序?
我想
你想要这样的东西:
SELECT * FROM (
SELECT id, user_id, post_id, other_id, 'favorite' as type, date FROM table1
UNION
SELECT id, user_id, post_id, other_id, 'like' as type, date FROM table2
UNION
SELECT id, user_id, post_id, other_id, 'comment' as type, date FROM table3
) AS t ORDER BY date