I have 4 tables, in table's 'tbl_Order'
has single record of each cusotmer. in table's 'tbl_OrderDetail'
there are more then 1 Services (records) of each customer. in table's 'tbl_services'
there are more then 10 pre-define services. inch table's 'tbl_users'
there are customer's basic information.
my question is : how I can fetch data by each customer using PHP with MySql. My tables details are below:
tbl_Order: Order_ID,Order_Type,Order_Date,Time,Customer_ID,Booking_Type,Booking_Status,Order_No,Car_No,Booking_Date
tbl_OrderDetail: ID,Order_ID,Service_ID
tbl_services : Service_ID,S_Name,S_Price
tbl_users : Customer_ID ,User_Name
您可以使用一个表的主键与另一个表的外键联接四个表,并且在查询的处仅使用User_Name的顺序
select *
from
tbl_Order a
inner join
tbl_OrderDetail b
on a.Order_ID = b.Order_ID
inner join
tbl_services c
on b.Service_ID = c.Service_ID
tbl_users d
on d.Customer_ID = c.Customer_ID
I would advice you to select the columns you want instead of using *
. EG : a.Order_ID, b.Service_ID
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.