Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Need help in a sql

Author  Topic 

gamaz2
Starting Member

31 Posts

Posted - 2014-06-18 : 13:55:14
I have the following scenario:
I have created the following test table to explain the current issue I am haivng.
ID EFFDT FIRST_NAME LAST_NAME
1 2/4/13 John Doe
1 4/3/14 John Doe1
2 1/1/98 Jane Doe
2 5/2/13 Jane Doe2
2 3/6/14 Jenny Doe2

I need to find the set using sql which will give unique ids with max effdt.

So the output should be


ID EFFDT FIRST_NAME LAST_NAME

1 4/3/14 John Doe1
2 3/6/14 Jenny Doe2

I appreciate any help on building this sql. Thanks.

Aivlis
Starting Member

6 Posts

Posted - 2014-06-18 : 14:00:14
Are you trying to make a SELECT or a PROCEDURE?

Be brave.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-06-18 : 14:00:46
As this appears to be a homework question, I'll provide a hint. You can use GROUP BY and MAX in a derived table or CTE. Or you can use ROW_NUMBER() function.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-06-18 : 14:01:36
quote:
Originally posted by Aivlis

Are you trying to make a SELECT or a PROCEDURE?



Aivlis, please edit your signature so that it does not include an avatar.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

gamaz2
Starting Member

31 Posts

Posted - 2014-06-18 : 14:31:17
I am trying to figure this out using sql. tkizer, this is a real issue I am tyring to figure out and not a home work as you are thinking.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-06-18 : 14:33:15
Show us what you have so far then.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -