If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Date Selection

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-03-06, 17:27
drshimbo drshimbo is offline
Registered User
 
Join Date: Apr 2006
Posts: 3
Question Date Selection

I have 20 rows in a database made up of 5 different names, so I have 4 rows with the same name the only difference being that they have a different date and address. How do I create a query to select the name and address based on the latest date for each of the different names.
Reply With Quote
  #2 (permalink)  
Old 04-04-06, 07:05
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Code:
select name, address
from   mytable t1
where  t1.datecol = (select max(t2.datecol)
                     from   mytable t2 
                     where  t2.name = t1.name
                    );
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 05-12-06, 16:30
drshimbo drshimbo is offline
Registered User
 
Join Date: Apr 2006
Posts: 3
Many thanks for the reply, tried it and it worked perfectly to give me the information I required.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On