sql - MySQL - "Most social User" with the most comments in multiple tables -
i have 2 tables of concern - 'videocomments', 'storycomments'.
i need find 'posterid' has entries in videocomments
, storycomments
. here's code have far, calls videocomments
:
$sql = "select (select posterid videocomments group posterid order count(posterid) desc limit 1) ) mostsocialuser ";
how pull , compare count of posterid both tables?
use:
select x.posterid, count(y.posterid) + count(z.posterid) numcomments (select vc.posterid videocomments vc union select sc.posterid storycomments sc) x left join videocomments y on y.posterid = x.posterid left join storycomments z on z.posterid = x.posterid group x.posterid order numcomments desc limit 1
Comments
Post a Comment