Wojtek Wencel
Wojtek Wencel

Reputation: 2127

How to make multiple table join?

I want to extract some data from my shop's database. The data I want is in four tables: ps_order_detail, ps_orders, ps_carrier and ps_customer. The main table is ps_order_detail. For each record of ps_order_detail I want to attach corresponding values from other tables based on id's: id_order, id_customer and id_carrier. The problem is that the base table (ps_order_detail) contains only id_order and the other id's are in ps_orders table. Do you know how can I solve this?

Upvotes: 0

Views: 28

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271151

Your question is unclear on the data layouts of the tables, but the query would look something like this:

select . . . 
from ps_order_detail od join
     ps_orders o
     using (id_order) join
     ps_customer c
     using (id_customer) join
     ps_carrier ca
     using (id_carrier)

Upvotes: 1

Related Questions