Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 28th, 2004, 09:04 AM
devthefirst devthefirst is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 devthefirst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy Want distinct row in query

Hi..All.

I can't get distinct row from query..i tried a lot but couldnt succeded. Let me
explain in brief.

I am having a table name usermaster. Having column..RID(autogen), Name, Date, Miniute.
Now when i tried to fetch rows between two dates, at that time it gives all rows between those
dates..What i want is uniq name with max date...for example
There are two rows...

id, name, date, min
1, Dev, 10/26/04, 20
2, Dev, 10/27/04, 30...

now i want the last rows to be fetched as its max date...when I tried query with date between
10/26/04 to 10/28/04..both row comes..

I used distinct, groupby, order by ...but it wont work...

Pls. pls. help me to sort it out..

Thanx.
Dev

Reply With Quote
  #2  
Old October 28th, 2004, 09:17 AM
Memnoch's Avatar
Memnoch Memnoch is online now
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,770 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 7 h 8 m 6 sec
Reputation Power: 469
Try this
Code:
SELECT DISTINCT Name, Max(sDate)
FROM Table1
WHERE sDate BETWEEN '10/26/2004' AND '10/28/2004'
GROUP BY Name

Reply With Quote
  #3  
Old October 29th, 2004, 03:57 AM
devthefirst devthefirst is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 devthefirst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanx Memnoch..

It really worked, but the problem is "i want all fileds in query". When i tried all field in select statement. It gives order by error. So i added those fileds in order by clause too..so same thing happend...I got both row in return..!! Please guide me to get all fields of table....???

Reply With Quote
  #4  
Old October 29th, 2004, 04:31 AM
devthefirst devthefirst is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 3 devthefirst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Hureey....

ThanX..memnoch. It worked..I changed the postion of field in select statement...and GOTCHA..what i want..

THANKS..A..LOT.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseMicrosoft SQL Server > Want distinct row in query


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT