Click here to Skip to main content
15,945,119 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
How to write the sql statement
to select the Price of latest order date from the Price talbe

Mohd. Mukhtar 21-Jan-13 4:55am    
What have you tried so for?
André Kraak 21-Jan-13 5:01am    
In order for us to help we need more information.
Please supply table structure (including primary key) and data sample (both table and expected result).

Based on your too less information
select top 1 price from PriceTable order by OrderDate Desc
Share this answer
__TR__ 21-Jan-13 5:27am    
Good answer. 5!
owencampbell 21-Jan-13 5:44am    
He mentions mysql so you'll have to use LIMIT 1 at the end instead of Top 1 but considering the lack of info s/he is lucky to get a response anyway.

select price from PriceTable order by OrderDate Desc limit 1
__TR__ 21-Jan-13 6:45am    
The subject of this question read
sql statement by mssql
So i am assuming its MS-SQL server. If the OP was looking for a solution in MySql s/he can refer your comment :)
Try IDENTITY to get the last inserted record.
Share this answer
Herman<T>.Instance 21-Jan-13 6:49am    
scope_identity() function you mean.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900