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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return lowest value

Status
Not open for further replies.

dbrunner281

Technical User
Jul 26, 2004
1
CH
Hi guys. My first post. I have a boss who basically doesn't want to hire a professional DBA to get things started with our company database. He threw me into it w/out any knowledge. I have a database that basically has records of all our sales invoices. I have three main tables. One is Customer Info which has a field called: customer since. It is a date data type. I am trying to return the date from the lowest numbered invoice of the particular customer. This data is in the Invoice table i have.

Does this make any sense? I am new to this so I apologize if this seems elementary or if I don't make any sense.
 
It doesn't you are going to want to do something like the following

Using the Northwind database as an example..

select c.ContactName, (SELECT min(OrderDate) FROM Orders WHERE CustomerID=c.CustomerID) as MinOrderDate
FROM Customers c (NOLOCK)

you'll want to use something like..

select c.CustomerName,c.CustomerSince, (SELECT min(Invoice) FROM Orders WHERE CustomerID=c.CustomerID) as MinOrderDate
FROM Customers c (NOLOCK)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top