L
L
lexstile2020-10-03 15:33:27
SQL
lexstile, 2020-10-03 15:33:27

Why does the query only return the record for the first condition?

SELECT events.id, events.name as event_name, events.date_start, events.date_end, events.country_id, events.description, events.day_1, events.day_2, events.month_1, events.month_2, events.year_1, events.year_2, events.is_present, links.links, images.images, countries.countries, clusters.clusters FROM events
    LEFT JOIN (SELECT countries.id, event_to_country.event_id, GROUP_CONCAT(countries.name) as countries FROM countries LEFT JOIN event_to_country ON countries.id = event_to_country.country_id GROUP BY event_to_country.event_id) as countries ON events.id = countries.event_id
    LEFT JOIN (SELECT event_id, GROUP_CONCAT(link) as links FROM links GROUP BY event_id) AS links ON events.id = links.event_id
    LEFT JOIN (SELECT event_id, GROUP_CONCAT(name) as images FROM images GROUP BY event_id) AS images ON events.id = images.event_id
    LEFT JOIN keywords ON events.id = keywords.event_id
    LEFT JOIN (SELECT country_id as c_id, GROUP_CONCAT(name) as clusters FROM clusters GROUP BY c_id) AS clusters ON countries.id = c_id
    WHERE countries.id = :country_id 
    ORDER BY events.year_1 ASC
    LIMIT 30

Here is the link table:
5f786ed7b58cd840016776.png
Works strangely, displays only events with the first link.
That is:
If countries.id = 2 - only the event with id 142 is displayed , but it should also be with id = 141 , since there is a connection.
Event id 141 is only emitted if you pass countries.id = 8 .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Gnevyshev, 2020-10-03
@lexstile

Maybe that's why?
GROUP BY

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question