PHP MySQL : How to select multiple tables and return output summary with good performance?

标签 php mysql performance multiple-tables

如何在 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) 获取 keycontent 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/

相关文章:

php - UNIX_TIMESTAMP() 和 time() 是否相同

php - 如何显示用户配置文件中的 acf 字段?

performance - Neo4j 遍历性能

php - 在mysql中存储html需要注意什么

mysql - 如何在 mysql 中查找所有无效 View ?

php - mysql 内连接查询优化

java - Java 是否适合 Multi-Tenancy SAAS 架构?

javascript - 如何将PHP Post数据放入jquery ajax请求中?

php - 在 PHP 中写入文本文件时换行不起作用

php - mysql 使用 group by 获取行值