select * from (select posts.* , users.email, users.fullname ,posts.date_listed as action_date ,'post' as type from posts , users where users.email= posts.username and users.email = union all select posts.* , users.email, users.fullname, posts_action.date as action_date , 'like' as type from posts , users , posts_action where users.email= posts.username and users.email = and posts_action.user_id = users.id and posts_action.post_id = posts.id and posts_action.action ='like' union all select posts.* , users.email, users.fullname, posts_action.date as action_date , 'dislike' as type from posts , users , posts_action where users.email= posts.username and users.email = and posts_action.user_id = users.id and posts_action.post_id = posts.id and posts_action.action ='dislike' union all select posts.* , users.email, users.fullname, posts_action.date as action_date , 'comment' as type from posts , users , posts_action where users.email= posts.username and users.email = and posts_action.user_id = users.id and posts_action.post_id = posts.id and posts_action.action ='comment') as posts order by action_date DESC limit 0,100You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'union all select posts.* , users.email, users.fullname, posts_action.date as ' at line 3