I have this SQL that works fine although a little slow. Ideally would like to have the extra sub query in the where clause something like this AND country_iso = “uk”.
SELECT c.content_name, c.content_telephone, c.content_address1
(SELECT w.weblink_url FROM weblinks w WHERE w.content_id = c.content_id ORDER BY w.weblink_ordering, w.weblink_id ASC LIMIT 1)
AS content_url,
(SELECT country_name FROM countries WHERE country_id = c.country_id LIMIT 1)
AS country_name,
(SELECT country_iso FROM countries WHERE country_id = c.country_id LIMIT 1)
AS country_iso
FROM catcontents cc
LEFT JOIN content c ON c.content_id = cc.content_id
WHERE cc.category_id = 7
AND (SELECT country_iso FROM countries WHERE country_id = c.country_id LIMIT 1) = 'uk'
ORDER BY cc.catcontent_ordering ASC, c.content_name ASC
Would this query not suit your needs? (basically, use joins to get the country, instead of sub-selects.)