如何在 PHP 上获取结果:
- NU61 - 太阳 - 2011
- KE2I - 球 - 2000
- B8WO - 点 - 2008
table_first SELECT id, order, date FROM table_first ORDER BY orders DESC
返回 id
, date
id | orders | date
------+---------+------
KE2I | 2 | 2000
B8WO | 5 | 2008
NU61 | 1 | 2011
table_second SELECT key FROM table_second WHERE id=(id from table_first)
获取 key
从 content
table_third
id | key
------+-----------------
KE2I | .b
B8WO | .p
NU61 | .s
table_third SELECT content FROM table_third WHERE id=(key from table_second)
返回 content
id | content
------+-----------------
.b | ball
.p | point
.s | sun
最佳答案
SELECT `table_first`.`id`,
`table_third`.`content`,
`table_first`.`date`
FROM `table_first`
LEFT JOIN `table_second` USING(`id`)
LEFT JOIN `table_third` ON `table_third`.`id`=`table_second`.`key`
只要您有索引,性能就不是问题:
`table_first`.`id`
`table_second`.`id`
`table_second`.`key`
`table_third`.`id`
关于PHP MySQL : How to select multiple tables and return output summary with good performance?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7947716/