2 tables: owners & cars
An owner can have many cars. A car can be marked as usable_offroad, usable_onroad, or both. The cars table has usable offroad and usable_onroad fields which can be set to 0 or 1 (no or yes)
Consider the following query:
SELECT *
FROM owners
LEFT JOIN cars on cars.owner_id = owners.id
GROUP BY owners.id
ORDER BY owners.last_name
My goal is to return a list of owners, and whether or not each owns a an onroad or offroad vehicle, or both:
Last Name First Name Has Offroad Car Has Onroad Car
----------------------------------------------------------------------
Smith Todd Yes No
Smith Tom Yes Yes
Test Sue No Yes
Thumb Joe No No
White Al Yes No
How do I query this? Was thinking of using ROLLUP, but would prefer if the summary wasn't an appended row but an actual field on the already grouped owner row instead.