Reputation: 1253
I have 3 similar tables with 1 different column
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
Is there a way to return all combined where user_id = 1 and order by date ?
Upvotes: 0
Views: 29
Reputation: 3150
I suppose you want something like this:
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
Upvotes: 1