Solved

Group By....Having

Posted on 1998-08-21
4
156 Views
Last Modified: 2010-03-19
I have the Data:

code   name     date
.........................
code1  namea    date1
code1  nameb    date2
code1  namec    date3
code2  namem    datex
code2  namen    datey
code2  nameo    datez

so on.........
I want result as

code1   name  max(date)
code2   name  max(date)


I want the details of each code,..... when Date is Max.

I have tried Group By with Having.
Anybody with sample code/syntax

Thanx
0
Comment
Question by:anilkumarv
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
connex earned 50 total points
ID: 1089679
SELECT CODE,NAME,MAX(date)
FROM TABLE
GROUP BY CODE,NAME

Should do it

0
 
LVL 5

Expert Comment

by:mayhew
ID: 1089680
If you're trying to just get the rows that have the max date for each code, you might want to try:

select code, name, date from table a
where date=(select max(date) from table b
           where a.code = b.code)

BTW, that's not a typo.  It's a double reference to the same table.

Let us know if you're looking for something else.   :)
0
 

Author Comment

by:anilkumarv
ID: 1089681
Thanx Mayhew
Your comment solved my probelm.
0
 
LVL 5

Expert Comment

by:mayhew
ID: 1089682
Glad to be of service.

BTW, if you want to award points to a comment, you can reject a previous answer and ask the comment poster to repost as an answer.  That way you can award points to the person that helped you.

Just wanted to let you know.  :)

Again, I'm glad it's working for you.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now