Results 1 to 9 of 9
Mar 21, 2013, 09:05 #1
- Join Date
- Dec 2004
- Yorkshire, England
- 0 Post(s)
- 0 Thread(s)
Query to return associated data and not what is searched for
I've written a query that is the equivalent of asking someone to go find a sock but to also return anything else they found along with it.
I have bookings, each of which have a one-to-many relationship with one to [n] data objects. While I'm asking the database to find one of those data objects, I actually need it to retrieve any other data objects it might find. Alas, it's not working that way and it's only returning what it's finding.
I've emboldened the part of the query which is the source of my angst.
I'm sure this is a very common problem, but I can't articulate the problem to even search for a solution!
As always, any advice would be warmly received.
SELECT bookings.booking_id, DATE_FORMAT(bookings.creation_date, '%a %D %b %y') AS creation_date, DATE_FORMAT(bookings.modification_date, '%a %D %b %y') AS modification_date, bookings.client_id, bookings_attendees.name, DATE_FORMAT(bookings_attendees.stay_date, '%a %D %b %y') AS stay_date, bookings_attendees.stay_nights, venues.venue_id AS venue_id, venues.name AS venue, venues.town_city, DATE_FORMAT(( SELECT MAX(bookings_history.modification_date) AS booking_history FROM bookings_history WHERE (bookings_history.booking_id = bookings.booking_id) ), '%a %D %b %y, %H:%i') AS booking_history, COALESCE(GROUP_CONCAT(DISTINCT bookings_clients_options_data.value SEPARATOR 0x1D), 'NULL') AS clients_options FROM bookings_attendees INNER JOIN bookings ON (bookings.booking_id = bookings_attendees.booking_id) AND (bookings.client_id = '3') AND (bookings.status = 'confirmed') AND (bookings.mode = 'public') INNER JOIN bookings_clients ON (bookings.booking_id = bookings_clients.booking_id) INNER JOIN clients ON (clients.client_id = bookings_clients.client_id) AND (clients.client_id = '1') INNER JOIN venues ON (venues.venue_id = bookings.venue_id) INNER JOIN bookings_clients_options ON (bookings_clients_options.client_id = '3') INNER JOIN bookings_clients_options_data ON (bookings_clients_options.bookings_client_option_id = bookings_clients_options_data.bookings_client_option_id) AND (bookings_clients_options_data.booking_attendee_id = bookings_attendees.booking_attendee_id) WHERE (bookings_clients_options_data.bookings_client_option_id = '4') GROUP BY bookings.booking_id ORDER BY bookings_attendees.stay_date ASC