I want to combine multiple tables result count in one result with column wise using MySql (see the result required) but i am confuse about this if you have any query or optimize way regarding this please answer me or helps are definitely appreciated also i was tried myself this Query with Union but seriously not success (see the Query Example)
Result required
post post_comment_likes post_comments post_likes
2 0 3 0
Query
SELECT COUNT(*) AS `post` FROM post WHERE user_id = "123456" UNION
SELECT COUNT(*) AS `post_comment_likes` FROM post_comment_likes WHERE user_id = "123456" UNION
SELECT COUNT(*) AS `post_comments` FROM post_comments WHERE user_id = "123456" UNION
SELECT COUNT(*) AS `post_likes` FROM post_likes WHERE user_id = "123456"
In the above code @post , @post_comment_likes , @post_comments , @post_likes are session variables , you prefix them with ‘@’ character
Using the above code you have access to count of each table.