Can anyone turn these statements, into a single query using JOIN... Or even a subquery if it would help with system resources? select id, title from table1 where (langs like '%$z_lang%'); // for each result, do this query: select count(*) from table2 where (lang = '$z_lang') and (category = ^ID_FROM_1ST_QUERY) and (status = 'active'); PHP: I'll give... $4... to the first one that sends me a working sql statement
select a.id, a.title, b.count(*) from table1 a inner join table2 b on a.id=b.category where b.lang = '$z_lang' and b.status= 'active' group by a.id, a.title; PHP: For better performance: Add an index to id and title in table1 and status, category, and langs in table2 Keep the $4.