Advertisement

06.22.2007 at 05:36AM PDT, ID: 22651025
[x]
Attachment Details

Select latest month from a sql table column

Asked by jawahar_prasad in SQL Server 2005, Databases Miscellaneous, MS SQL Server

Tags: sql, select, latest

Hi..
I have the following table

tbl1

tid primary key int
catid numeric(5)
product_id numeric(5)
tmonth varchar(255)

values

tid    catid   product_id    tmonth
1      1         1                  January
2      1         1                  February
3      2         1                  April
4      2         1                  May
6      3         1                  Quarter1
7      3         1                  Quarter2

I want the output to be :

tid    catid   product_id    tmonth
2      1         1                  February
3      2         1                  May
7      3         1                  Quarter2

The above result is similar to running a query like this..
select tid,catid,product_id,max(tmonth) from tbl1 group by catid,product_id,tid <--??

BUT it wont work because , max(tmonth) is not correct... and group by tid is not correct!!!!

Please provide the correct query...
(IT should be in a single select statement)Start Free Trial
[+][-]06.22.2007 at 05:47AM PDT, ID: 19340762

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.22.2007 at 05:54AM PDT, ID: 19340799

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.22.2007 at 06:01AM PDT, ID: 19340855

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.22.2007 at 06:58AM PDT, ID: 19341329

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.22.2007 at 11:20AM PDT, ID: 19343591

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.22.2007 at 12:49PM PDT, ID: 19344339

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.22.2007 at 01:03PM PDT, ID: 19344420

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.22.2007 at 02:30PM PDT, ID: 19345027

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Server 2005, Databases Miscellaneous, MS SQL Server
Tags: sql, select, latest
Sign Up Now!
Solution Provided By: ScottPletcher
Participating Experts: 5
Solution Grade: A
 
 
[+][-]06.22.2007 at 02:32PM PDT, ID: 19345040

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.22.2007 at 10:04PM PDT, ID: 19346542

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32