Answer the question
In order to leave comments, you need to log in
How else to optimize a query with a subselect?
Good day to all.
There is a task: We have a lot of cities and announcements of events in them. You need to display a list of all cities that have ever had announcements and next to it, the number of upcoming (greater than or equal to the current date) announcements in a particular city.
There is a request like this:
select c.id, c.name, count(n.id) from main_city c left join main_news n on (c.id=n.city and n.moder=1 and n.date>=DATE_FORMAT($now_city_date,'%Y%m%d') )
group by c.id order by c.sort,c.name
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question