Blog

MySQL LEFT JOIN and WHERE Example
Posted on July 7, 2015 in MySQL by Matt Jennings

Consider a user_quotes MySQL database with the three tables below:

  • users
  • quotes
  • favorites (one to many relationship with the users and quotes tables)

The MySQL query below, with LEFT JOIN and WHERE, will select all quotes from a the favorites table where favorites.user_id = 5 and display them:

SELECT favorites.quote_id, favorites.user_id, quotes.quote, quotes.quoted_by FROM favorites 
LEFT JOIN quotes ON quotes.id = favorites.quote_id 
WHERE favorites.user_id = 5

Leave a Reply

To Top ↑