Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Use of Where and having clause

780459Jun 21 2010 — edited Jun 21 2010
Hi all,

I always have a doubt about use of HAVING and WHERE clause,
suppose I have table T1 with only one column C1

CREATE TABLE T1
(C1 VARCHAR2(1) );

which having data by following INSERT scripts

INSERT INTO T1 VALUES('A');
INSERT INTO T1 VALUES('B');

INSERT INTO T1 VALUES('C');

INSERT INTO T1 VALUES('A');
INSERT INTO T1 VALUES('B');

INSERT INTO T1 VALUES('A');


Now I want result as follows



C1 ==== COUNT(C1)
==============
B ===== 2
A ===== 3

So out of query 1 and 2 which approach is right ?

1) SELECT C1,COUNT(C1) FROM T1
WHERE C1<>'C'
GROUP BY C1
ORDER BY C1 DESC;

2) SELECT C1,COUNT(C1) FROM T1
GROUP BY C1
HAVING C1<>'C'
ORDER BY C1 DESC;

Edited by: user13306874 on Jun 21, 2010 2:36 AM
This post has been answered by Toon Koppelaars on Jun 21 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 19 2010
Added on Jun 21 2010
2 comments
607 views