Why do you have q.user
and q.userid
?
For option 2 (the best IMO option - if you pointed it out correctly), I think UNION
more than what you are looking for. Something like that:
SELECT 'question' AS action, id, created FROM questions WHERE userid = {$userid} UNION SELECT 'answer' AS action, id, created FROM answers WHERE userid = {$userid} UNION SELECT 'comment' AS action, id, created FROM answer_comments WHERE userid = {$userid} ORDER BY created DESC LIMIT 20
'question' / 'answer' / 'comment'
tells what action was taken. Possible problems you may encounter: UNION
, each SELECT
must have the same number of columns, so if one of them is short, you can simply add NULL
for example:
SELECT 'comment', id, created, NULL FROM ac
Alternatively, if one of the created
columns has a different name, you can simply alias
SELECT 'comment', id, comment_date AS created FROM ac
source share