[英]Sql query from related tables
I have 3 tables: 我有3张桌子:
shopping: 购物:
id buyer fruit
1 1 [->] 2 [->]
2 2 [->] 2 [->]
fruits: 水果:
id fruit
1 apple
2 banana
buyers: 买家:
id buyer
1 ido
2 omri
I want to extract from the table of 'shopping' and put the values of the other tables in the row. 我想从'shopping'表中提取并将其他表的值放在行中。 For example: Row number one in 'shopping' should look like this: 例如:'shopping'中的第一行应如下所示:
id buyer fruit
1 ido banana
You just need to join the related tables on their respective IDs: 您只需要在各自的ID上加入相关表:
SELECT s.id, b.buyer, f.fruit
FROM shopping s
JOIN fruits f ON s.fruit = f.id
JOIN buyers b ON s.buyer = b.id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.