Latest date SQL

5 pts.
Tags:
Database programming
SQL
Hi I am Trying to grab only the latest date from a uniquie stock number wich has mutiple dates? All i want to show is the lastest date against the stock number. Bear in mind that theese are comming from two different tables. Any Ideas
ASKED: August 7, 2008  9:33 AM
UPDATED: September 21, 2011  9:36 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Try This

Select S.StockNo,D. Date From StockTable S
Join StockDate D On D.StockNo=S.StockNo
Order By D.Date Desc

————–

I believe this is more along the lines of what the OP is looking for.

<pre>SELECT StockId, Max(Date)
FROM (SELECT StockId, max(Date)
FROM FirstTable
GROUP BY StockId
UNION ALL
SELECT StockId, max(Date)
FROM SecondTable
GROUP BY StockId) a
GROUP BY StockId</pre>

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following