Solved

Group By....Having

Posted on 1998-08-21
4
155 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
Comment Utility
SELECT CODE,NAME,MAX(date)
FROM TABLE
GROUP BY CODE,NAME

Should do it

0
 
LVL 5

Expert Comment

by:mayhew
Comment Utility
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
Comment Utility
Thanx Mayhew
Your comment solved my probelm.
0
 
LVL 5

Expert Comment

by:mayhew
Comment Utility
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

771 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

10 Experts available now in Live!

Get 1:1 Help Now