Like the question says is there a better way to write this:

就像问题所说有更好的方法来写这个:

SELECT clients_lists.*, 
       COUNT(clients_lists_relationships.clientid) 
FROM   clients_lists 
       LEFT JOIN clients_lists_relationships 
         ON clients_lists.listid = clients_lists_relationships.listid 
WHERE  clients_lists.parentid = 1 
GROUP  BY clients_lists.listid; 

1 个解决方案

#1


3

Not really. The query looks fine to me. You can try to use aliases for better readability:

不是真的。查询看起来很好。您可以尝试使用别名以获得更好的可读性:

SELECT c.*, 
       COUNT(r.clientid) 
FROM   clients_lists c
       LEFT JOIN clients_lists_relationships r
         ON c.listid = r.listid 
WHERE  c.parentid = 1 
GROUP  BY c.listid;

But it won't really make a technical difference (not that I know).

但它不会真正产生技术差异(不是我所知道的)。

Also make sure that both clients_lists.listid and clients_lists_relationships.listid are of the same datatype and length and are indexed. This will definitely help your query's performance.

还要确保clients_lists.listid和clients_lists_relationships.listid具有相同的数据类型和长度并且已编制索引。这肯定有助于查询的性能。

更多相关文章

  1. Mysql Where使用列别名
  2. MySQL数据库表名、列名、别名区分大小写的问题
  3. 在Delete From语句中带有别名的表变量。
  4. 在SQL SELECT语句中重用别名字段
  5. 每个派生表必须有自己的别名(sql&php)[重复]
  6. SQL文结果集起别名

随机推荐

  1. Activity属性设置大全
  2. Android GridView 使用示例
  3. 从零开始--系统深入学习android(实践-让我
  4. android检测当前网络是否可用
  5. Android笔记_Linearlayout(线性布局)
  6. Android全屏显示的两种方式
  7. Android进程 与 消息模型
  8. android应用程序签名问题
  9. Android杂谈---Android几种预定义样式
  10. 开机关机动画工作流程