Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Distinctrow issues

Status
Not open for further replies.

asrg

Technical User
Jul 11, 2011
9
GB
Hi .. I'm new to SQL and trying to do the following:
I have 2 tables, tblcustomer and tblorders.
I want the output to show the last order (tblorders.orderdate) date of the individual customers
===================================================
Select DistinctRow
tblcustomer.surname
From
tblcustomer Inner Join
tblorders On tblcustomer.CustID = tblorders.CustID
Order By
tblcustomer.surname
==================================================
I get an output thats just a list of customers that have an order, but doesnt show any details, the last order date..

Help :)
 
Are you sure you asked in the right forum?
This is SQL Server forum and SQL Server does not have DistinctRow clause.

BTW if you want to get the record with the bigger date and the order detail try this:
Code:
Select * -- put the field list here
From tblorders
Inner Join tblcustomer On tblcustomer.CustID = tblorders.CustID
Inner Join (SELECT CustID, MAX(orderdate) AS orderdate
                   From tblorders
            GROUP BY ) Tbl1 
           ON tblorders.CustID    = Tbl1..CustID AND
              tblorders.orderdate = Tbl1.orderdate
Order By tblcustomer.surname

Borislav Borissov
VFP9 SP2, SQL Server 2000,2005 & 2008.
 
Hey thanks buddy ... Im from Access background and trying to up my game.

Works fine .. many thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top