Current location: Hot Scripts Forums » Other Discussions » Database » select last date


select last date

Reply
  #1 (permalink)  
Old 04-03-11, 08:47 AM
altarek's Avatar
altarek altarek is offline
Newbie Coder
 
Join Date: Dec 2010
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
select last date

hello

i have table like this and want to display the row of last date (repeated id)
for example want to have row (2007 and 2009)

id |date
-----------
1 | 2005
1 | 2007
2 | 2008
2 | 2009
any help
Reply With Quote
  #2 (permalink)  
Old 04-03-11, 12:41 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
SELECT date FROM table ORDER BY date DESC LIMIT 1
Reply With Quote
  #3 (permalink)  
Old 04-04-11, 01:47 AM
altarek's Avatar
altarek altarek is offline
Newbie Coder
 
Join Date: Dec 2010
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
This returns a single result and I want to retrieve a single result for each duplicate id
i want to retrieves rows with years(2007 and 2009)
Reply With Quote
  #4 (permalink)  
Old 04-04-11, 02:38 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Okay, sorry! Give this a try

Code:
SELECT DISTINCT `date` FROM `table` ORDER BY `date` DESC LIMIT 2
Reply With Quote
  #5 (permalink)  
Old 04-04-11, 02:49 AM
altarek's Avatar
altarek altarek is offline
Newbie Coder
 
Join Date: Dec 2010
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
and if duplicated id more than 2 or id i don't know number of duplicated id
Reply With Quote
  #6 (permalink)  
Old 04-08-11, 08:16 PM
nafirici nafirici is offline
Newbie Coder
 
Join Date: Mar 2011
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
you could try order by and group by. It's not really what it's meant for, but it might work. I accidentally did this just yesterday while playing with a query, I ended up with a result set similar to what you're looking for. Also, you might want to look further into it, because the result set might not be guaranteed.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date in VB getting format right? budemeadows Visual Basic 6 11-13-08 09:33 AM
select date from mysql class ? medo PHP 7 12-02-07 04:24 PM
MYSQL Error - Date select problem vivabensmith PHP 2 10-16-07 03:02 AM
converting date-string to Date object UnrealEd Everything Java 4 05-15-07 06:20 PM
Using list/menu to select date dynamically dihan PHP 8 04-28-05 07:07 PM


All times are GMT -5. The time now is 05:16 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.