Home > database >  A one-to-many relationship, how to operate
A one-to-many relationship, how to operate

Time:09-16

There are two tables, a luser, is to save the user information table, there are two fields l8 l9, another table XBK, hobbies,

I want to l8 l9 display name for the corresponding hobby Chinese characters, how to operate

CodePudding user response:

SELCT [luser] * [XBK] KC_NAME FROM [luser], [XBK] wehere [luser] L8=[XBK]. ID

CodePudding user response:

Thank eaqpi answer, according to your suggestion only show the l8, l9 did not show, I am need l8 l9 shows at the same time

CodePudding user response:

 SELECT * FROM XBK AS A 
LEFT the JOIN IUser AS u1 ON Anderson, 8=u1. Id
LEFT the JOIN IUser AS u2 ON Anderson, 9=u2. Id

CodePudding user response:

 SELECT A. * 
, u1. Kc_name AS I8_name
, u2. Kc_name AS I9_name
The FROM XBK AS A
LEFT the JOIN IUser AS u1 ON Anderson, 8=u1. Id
LEFT the JOIN IUser AS u2 ON Anderson, 9=u2. Id

CodePudding user response:

I think I9 need corresponding to the other table,

Behind the from [XBK] as xb, behind the where use alias LUSER. L9=xb. ID

CodePudding user response:

That there are a lot of ways, left the join, can also be embedded (select XXX) can also be directly,
  • Related