database - MySQL: looking to SUM these UNIONs together -
ok, head hurts...!
this beautiful mysql query:
(select mtwitterfollowers twitfollow `media` media.id=1) union (select sum(twitterfollowers) twitfollow people left join peoplejoin on peoplejoin.people_id = people.id left join positions on position_id = positions.id peoplejoin.media_id = 1) union (select sum(twitterfollowers) twitfollow people left join peoplejoin on peoplejoin.people_id = people.id left join networkjoin on networkjoin.network_id = peoplejoin.network_id left join positions on position_id = positions.id networkjoin.media_id = 1)
...returns 3 rows of pretty numbers.
ideally, i'd query return 3 "twitfollow" results, summed together.
however, putting sum round them gives me error "every derived table must have own alias", , i'm little confused quite how solve that.
(of course, sum results in php; assuming it's quicker using mysql server. right?)
use entire query from
clause of query:
select sum(twitfollow) ( (select mtwitterfollowers twitfollow `media` media.id=1) union (select sum(twitterfollowers) twitfollow people left join peoplejoin on peoplejoin.people_id = people.id left join positions on position_id = positions.id peoplejoin.media_id = 1) union (select sum(twitterfollowers) twitfollow people left join peoplejoin on peoplejoin.people_id = people.id left join networkjoin on networkjoin.network_id = peoplejoin.network_id left join positions on position_id = positions.id networkjoin.media_id = 1) ) t1
i changed union
union all
don't want remove rows because sum 1 table equal sum table.
Comments
Post a Comment