I have an application that uses a MySQL database to store, asking other things, meetings and projects. A project can have zero-to-many meetings, and a meeting can have zero-to-many projects. To assist with linking meetings to a project, I'm trying to write a single clean query that searches across all of these tables and their relations (e.g. projects have tasks, meetings have attendees)
Here's an idea of the design:
project - id - reference - description - type
project_meetings - id - project_id - meeting_id - created_at - created_by
meeting - id - reference
meeting_attendee - id - meeting_id - person_id
person - id - name
project_tasks - id - project_id - task_type_id - content
task_types - id - task_title
The simplest idea I had was using LEFT JOINs, but I found it removes the results from the tables with zero related objects. The two ways that work are to use UNIONs, subqueries, or a really horrible WHERE-AND-OR clause with brackets for Africa.
Can anyone suggest a better query pattern for this design, or a better design?