Answer the question
In order to leave comments, you need to log in
How to merge two SQL queries into one?
I have a query:
$db->query( "SELECT p.id, p.date, p.title, p.category, p.country, p.autor, p.alt_name, p.comm_num, p.approve, p.fixed, e.news_read, e.votes, e.user_id, e.need_pass FROM " . PREFIX . "_post p LEFT JOIN " . PREFIX . "_post_extras e ON (p.id=e.news_id) " . $where . " ORDER BY " . $order_by . " LIMIT {$start_from},{$news_per_page}" );
Answer the question
In order to leave comments, you need to log in
In my opinion, it would be more correct to merge in PHP: the table of countries is obviously small, it can be unloaded and cached as an ID => NAME array. Then just substitute the name in PHP instead of the ID.
Of course, you can do it in sql, but it will be ugly and not very productive.
As usual - a crooked storage structure leads to processing problems.
SELECT p.*, GROUP_CONCAT(c.name) countries
FROM p
JOIN с ON FIND_IN_SET(c.id, p.country)
GROUP BY p.id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question