File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Having Clause can work without group by

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not know that having can be used without group by in the select list.

But Oracle docs made it clear that having can work without group by also.

The HAVING clause is applied to each group of the grouped table, much as a WHERE clause is applied to a select list. If there is no GROUP BY clause, the HAVING clause is applied to the entire result as a single group.


create table gotcha(id number);
insert into gotcha values(1);
insert into gotcha values(2);
insert into gotcha values(1);

select count(*)
from gotcha
having count(*) > 3;

no rows selected

select count(*)
from gotcha
having count(*) >2

count(*)
----------
3
 
Roger Sterling
Ranch Hand
Posts: 426
Eclipse IDE Fedora Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea, Oracle may work without a Group but Santa Clause needs a Group. Elf, there's just too much work to do by himself.
 
chris webster
Bartender
Pie
Posts: 2369
31
Linux Oracle Postgres Database Python Scala
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is an implicit group in your results i.e. a single group including the entire set of data that you're fetching, because you haven't specified any other group. I can't think of many situations where using a HAVING clause without an explicit GROUP BY would be especially useful, though.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic