Home > database >  Questions about mysql associated multi-table query
Questions about mysql associated multi-table query

Time:04-23

Assuming that there is a table, structure for

 
The create table user_info {
Id int primary key,
The name varchar (20)
}

The create table order_info {
Id int primary key,
Order_user_id int,
Examine_user_id int
}

User_info is a user table, order_info through order_user_id, examine_user_id associated user table, now my demand is that the query only once user_info, to query the order_user_id and examine_user_id respectively by the corresponding user name
Similar

 
Select

The from
User_info user_info, order_info order_info

Could you tell me how to write SQL to?

CodePudding user response:

SELECT * FROM ` jssb_user ` u LEFT JOIN ` jssb_subscribe_order ` o ON u.i d=o.u ser_id LEFT JOIN ` jssb_subscribe_order ` a ON u.i d=a.c addie_id WHERE o.a id=2 for your database and the corresponding conditions jssb_user=user_info jssb_subscribe_order=order_info

CodePudding user response:

reference 1/f, spongebob squarepants L reply:
SELECT * FROM ` jssb_user ` u LEFT JOIN ` jssb_subscribe_order ` o ON u.i d=o.u ser_id LEFT JOIN ` jssb_subscribe_order ` a ON u.i d=a.c addie_id WHERE o.a id=2 for your database and the corresponding conditions jssb_user=user_info jssb_subscribe_order=order_info

If order_user_id and examine_user_id should be displayed separately, that is, to find out the two user name column,
  • Related