Suppose I have a table days which specifies the breakfast food and dinner food for each day, using IDs that point to a table food which contains the food names. How do I fetch the breakfast and dinner food names using a single query? Basically I want to combine the following into one query:
SELECT days.*, food.name AS breakfast_name FROM days, food WHERE days.breakfast_id = food.id AND days.id = '12'
SELECT days.*, food.name AS dinner_name FROM days, food WHERE days.dinner_id = food.id AND days.id = '12'
daysandfoodwith some kind oftypecolumn that can be used for grouping like this. You've violated the Zero, One or Infinity Rule by having two join columns.