You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

How-to-retrieve-data-from-two-or-more-tables.sql 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. -- Exercise 1
  2. SELECT category_name, product_name, list_price
  3. FROM categories c JOIN products p
  4. ON c.category_id = p.category_id
  5. ORDER BY category_name,product_name ASC;
  6. -- Exercise 2
  7. SELECT first_name, last_name, line1, city, state, zip_code
  8. FROM customers c JOIN addresses a
  9. ON c.customer_id = a.customer_id
  10. WHERE state='NJ'
  11. ORDER BY customers ASC;
  12. -- Exercise 3
  13. SELECT first_name, last_name, line1, city, state, zip_code
  14. FROM customers c JOIN addresses a
  15. ON c.customer_id = a.customer_id
  16. ORDER BY first_name ASC;
  17. -- Exercise 4
  18. SELECT last_name, first_name, order_date, product_name, item_price, discount_amount, quantity
  19. FROM customers c JOIN products p AND orders o JOIN order_items i
  20. ON c.customer_id = p.category_id AND o.order_id = i.order_id
  21. ORDER BY last_name, order_date, product_name ASC;
  22. -- Exercise 5
  23. SELECT product_name, list_price
  24. FROM products(
  25. SELECT product_name, list_price
  26. FROM products)
  27. ORDER BY product_name ASC;
  28. -- Exercise 6
  29. SELECT product_name, list_price
  30. FROM products(
  31. SELECT product_name, list_price
  32. FROM products)
  33. WHERE product_name IS null
  34. ORDER BY product_name ASC;
  35. -- Exercise 7
  36. SELECT ship_date, order_id, order_date
  37. FROM orders;