I have two issues.
I have simplified the tables involved.
Issue1.
advertisers is a table with two columns unique id and name
views is a table with two columns id and advtid
msgs is a table with two columns id and advtid
How do I fetch only those advertisers who have atleast one msg or one view and order by total msgs + total views?
I tried the following
select advertisers.*,views.*,msgs.* count(views.advtid) as totviews,count(msgs.advtid) as totmsgs sum(totviews+totmsgs) as finaltotal from advertisers,views,msgs where advertisers.id=views.advtid or advertisers.id = msgs.advtid order by finaltotal desc
This is not working, the mysql error says totviews column not defined.
Issue 2.
select advertisers.*,views.*,msgs.* from advertisers,views,msgs where advertisers.id=views.advtid or advertisers.id = msgs.advtid order by advertisers.id
The above works but takes too long to load, any ways to optimize this query?
Any solutions?