Wednesday, February 22, 2006

ORACLE SQL TIP OF THE DAY

You know, sometimes you just do the dumbest things because you never bothered looking into simplifying the task. Lets say you have a table full of data and you want to retrieve all duplicates. Well this is how i used to do it.

select *
from ( select mydata, count(*) thecount
from mytable
group by mydata)
where thecount > 1;

Well thats just DUMB DUMB DUMB!!!!

I can write instead:

select mydata, count(*)
from mytable
group by mydata having count(*) > 1;


much much better!!

3 comments:

Anonymous said...

I do find this useful. I guess I'm a geek. Do I ever miss my Oracle days. ;o)

Gabriel Robichaud said...

There is nothing wrong with being a geek. I have dedicated my entire life to making sure that I stay a geek. Born a geek, die a geek!

Anonymous said...

Ben, oui, mais t'avais qu'à me téléphoner, je te l'aurais donné ce truc!

Josée B.