Unix Technical Forum

SQL guestion finding duplicates

This is a discussion on SQL guestion finding duplicates within the Oracle Database forums, part of the Database Server Software category; --> Hello, I have a SQL question. Consider the following table... ---------------------- | Employee | ---------------------- | Name | Birthdate ...


Go Back   Unix Technical Forum > Database Server Software > Oracle Database

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-24-2008, 02:51 PM
Adam Sandler
 
Posts: n/a
Default SQL guestion finding duplicates

Hello,

I have a SQL question. Consider the following table...

----------------------
| Employee |
----------------------
| Name | Birthdate |
----------------------
| Joe | 1 July |
| Sue | 10 Aug |
| Mark | 15 Sep |
| Jane | 10 Aug |
----------------------

I'd like to find out all the employees who share the same birthday. I
was thinking initially that if I used SQL HAVING that would work... but
then I thought (from what I understand about the command) HAVING only
works on arithmetic operators. Also if I set up a condition with
WHERE, wouldn't that imply some previous knowledge of the birthdays?

My development background screams doing some kind of string compare or
regular expression matching but that could either get complicated or
perform poorly if the employee table had thousands of rows.

At any rate, how could I write a SQL statement to return all the names
(and birthdates) of employees with identical birthdays?

Thanks!!!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-24-2008, 02:51 PM
IANAL_VISTA
 
Posts: n/a
Default Re: SQL guestion finding duplicates

"Adam Sandler" <corn29@excite.com> wrote in
news:1121092714.729379.239250@g47g2000cwa.googlegr oups.com:

> Hello,
>
> I have a SQL question. Consider the following table...
>
> ----------------------
>| Employee |
> ----------------------
>| Name | Birthdate |
> ----------------------
>| Joe | 1 July |
>| Sue | 10 Aug |
>| Mark | 15 Sep |
>| Jane | 10 Aug |
> ----------------------
>
> I'd like to find out all the employees who share the same birthday. I
> was thinking initially that if I used SQL HAVING that would work... but
> then I thought (from what I understand about the command) HAVING only
> works on arithmetic operators. Also if I set up a condition with
> WHERE, wouldn't that imply some previous knowledge of the birthdays?
>
> My development background screams doing some kind of string compare or
> regular expression matching but that could either get complicated or
> perform poorly if the employee table had thousands of rows.
>
> At any rate, how could I write a SQL statement to return all the names
> (and birthdates) of employees with identical birthdays?
>
> Thanks!!!
>
>


HAVING COUNT(*) > 1
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-24-2008, 02:51 PM
Maxim Demenko
 
Posts: n/a
Default Re: SQL guestion finding duplicates

Adam Sandler wrote:
> Hello,
>
> I have a SQL question. Consider the following table...
>
> ----------------------
> | Employee |
> ----------------------
> | Name | Birthdate |
> ----------------------
> | Joe | 1 July |
> | Sue | 10 Aug |
> | Mark | 15 Sep |
> | Jane | 10 Aug |
> ----------------------
>
> I'd like to find out all the employees who share the same birthday. I
> was thinking initially that if I used SQL HAVING that would work... but
> then I thought (from what I understand about the command) HAVING only
> works on arithmetic operators. Also if I set up a condition with
> WHERE, wouldn't that imply some previous knowledge of the birthdays?
>
> My development background screams doing some kind of string compare or
> regular expression matching but that could either get complicated or
> perform poorly if the employee table had thousands of rows.
>
> At any rate, how could I write a SQL statement to return all the names
> (and birthdates) of employees with identical birthdays?
>
> Thanks!!!
>


Returns all employees sharing particular birth date:
select * from employee where birthdate='PARTICULAR_BIRTH_DATE'

Returns all employess where at least 2 employees share identical birth date:
select name,birthdate
from ( select count(*) over(partition by birthdate) cnt,name,birthdate
from employees )
where cnt > 1

In general take a look on analytical functions

Best regards

Maxim
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:44 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com