Skip to Main Content
  • Questions
  • difference b/w (decode and case),(where and having clause) and (join and subquery)

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, kuldeep.

Asked: May 22, 2016 - 12:45 pm UTC

Last updated: May 23, 2016 - 2:39 am UTC

Version: 11g

Viewed 1000+ times

You Asked

Sir,
Please tell me the exact difference b/w (decode and case),(where and having clause) and (join and subquery).

-
Thanks


and Connor said...

1)

DECODE is a subset of CASE. We had DECODE a long time before we introduced the CASE function, which is why a lot of people are more familiar with DECODE.

DECODE only "looks" at one thing, the first argument:

DECODE([the thing I'm looking at], [then the possible values])

whereas CASE could have many things to consider,

CASE
WHEN x=1 THEN
WHEN z+y < sysdate THEN
etc etc


2) HAVING is a where clause applied to an aggregation, for exmaple

select dept, count(*)
from emp
group by dept

I dont *know* the value of 'count(*)' until *after* I have done the group-by, so I can either do:

select dept, count(*)
from emp
group by dept
HAVING count(*) > 10

or

select *
from (
select dept, count(*) c
from emp
group by dept
)
where c > 10

3)

http://www.oracle.com/technetwork/issue-archive/2016/16-jan/o16sql201-2882217.html

http://www.oracle.com/technetwork/issue-archive/2016/16-mar/o26sql201-2952436.html



Is this answer out of date? If it is, please let us know via a Comment