SQL Server - sql query - Asked By Souniel Gaikwad on 07-Jan-11 03:46 PM

I trying to find last date from my table  given below
   consumer_no          delivery_date
       1001             1/12/2011
        1005            5/12/2010
       1001             31/12/2010
       1001             25/1/2011
I cant understand how to get last delivery_date means 25/1/2011 of consumer_no 1001
Peter Bromberg replied to Souniel Gaikwad on 07-Jan-11 04:12 PM
select top 1 delivery_date from tablename order by delivery_date Desc
Mitesh Darji replied to Souniel Gaikwad on 07-Jan-11 07:22 PM
select top 1 delivery_date from tablename where consumer_no=1001 order by delivery_date Desc 
user 00009 replied to Souniel Gaikwad on 08-Jan-11 03:53 AM
Hi Souniel Gaikwad,

Order the date in descending order and just select the top from it.

For example use

select top 1 date from yourtable order by date Desc
Souniel Gaikwad replied to Peter Bromberg on 08-Jan-11 01:44 PM
sorry sir but this query is not correct . plz sir tell me other queries for my table
Souniel Gaikwad replied to Souniel Gaikwad on 10-Jan-11 03:49 AM
I trying to find last date from my table  given below
   consumer_no      delivery_date
     1001       1/12/2011
      1005        5/12/2010
     1001       31/12/2010
     1001       25/1/2011
the above table is not ordered .I cant understand how to get last delivery_date means 25/1/2011 of consumer_no 1001
 
displaying Last delivery_date - Lalitha Kumaran replied to Souniel Gaikwad on 11-Jan-11 11:46 PM

Hope the below query help u to find out the last delivery_date.

select max(delivery_date) from test

Result:

This query returns the delivery date as 25/1/2011

select delivery_date,consumer_no from test where delivery_date in(
select max(delivery_date) from test)

Result:


This Query returns the delivery date along with customer no

Delivery_Date      Customer_No
25/1/2011              1011