Solved

Group By....Having

Posted on 1998-08-21
4
158 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

762 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