MySql-在哪里 [英] MySql - HAVING vs WHERE

查看:85
本文介绍了MySql-在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个查询有什么区别?

What is the difference between these 2 queries?

SELECT f.name, 
       u.name, 
       u.id 
FROM   families f 
       JOIN units u 
         ON f.unit_id = u.id 
HAVING u.id IN( 43, 413, 22 )

并且:

SELECT f.name, 
       u.name, 
       u.id 
FROM   families f 
       JOIN units u 
         ON f.unit_id = u.id 
WHERE  u.id IN( 43, 413, 22 )

这两个查询的结果完全相同.那有什么区别呢?

The result of these 2 queries is exactly the same. So where is the difference?

推荐答案

sql中的having和where子句之间的区别是where子句不能与聚合一起使用,但是having子句可以使用.一种考虑方式是,having子句是where子句的附加过滤器.

Difference between the having and where clause in sql is that the where clause can not be used with aggregates, but the having clause can. One way to think of it is that the having clause is an additional filter to the where clause.

哪个更好:点击

这篇关于MySql-在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆