Table Joins
Use orders.db to complete the following queries:
orders.dbjoins1.sql
SELECT * FROM menu JOIN orders ON menu.title == orders.title
joins2.sql
SELECT orders.customer_name, SUM(menu.price*orders.quantity) AS "Amount owing" FROM menu JOIN orders ON menu.title == orders.title GROUP BY orders.customer_name
joins3.sql
SELECT orders.customer_name, menu.category FROM orders LEFT JOIN menu ON menu.title == orders.titleThe default join in SQLite is an inner join. When you use the keyword
JOIN
, you can interchange this with INNER JOIN
as this is what the word JOIN defaults to:The bottom SQL join example (above) shows a
LEFT
join in action:Note the table on the left of the
LEFT
is all inclusive of records, in addition to the equal records to the table on the right.You are welcome to research other types of joins at your leisure (such as cross joins for example). It is likely though that the above joins will be all you will need for your studies to date.