Hello, how to link 3 tables in a SQL query? I have such a query (links 2 tables)

SELECT categories.title, goods.name, goods.id FROM categories INNER JOIN goods ON categories.id = goods.category ORDER BY categories.id; 

you need to link the orders table (orders.items_id link with goods.id)

table structure:

  categories |  goods |  orders
  --------- | -------------- | -------------
  id (Pk) |  id (Pk) |  id (Pk)
  title |  name |  items_id
  ---- |  category |  ---
  • show the structure of the tables themselves in subd - Ep1demic
  • @ Ep1demic corrected - Merlin

1 answer 1

If I am not mistaken

 SELECT categories.title, goods.name, goods.id FROM (categories INNER JOIN goods ON categories.id = goods.category) INNER JOIN orders ON orders.items_id = goods.id ORDER BY categories.id; 
  • FROM brackets desirable to remove ... - Akina