简体   繁体   中英

inner join with two tables in mySQL

i have two tables equipment and equipmenthistory.

equipment contains serialNum and status column and serialNum is primary key of that table.

equipmenthistory contains id, serialNum and status.. id is primary key of that table.

equipmenthistory table contain multiple rows with same serialNum

i need equipment.serialNum , equipment.status and list of equipmenthistory where serialNum  is same

Please help me to solve it. i wana do it with inner join.

The two options provide the same results. The first is shorthand for the second option.

Option 1

Select equipment.serialNum, equipment.status, equipmenthistory.id, equipmenthistory.serialNum,  equipmenthistory.status
From equipment
Inner Join  equipmenthistory using(serialNum)

Option 2

Select equipment.serialNum, equipment.status, equipmenthistory.id, equipmenthistory.serialNum,  equipmenthistory.status
From equipment
Inner Join  equipmenthistory 
On equipment.serialNum = equipmenthistory.serialNum

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM