Most Recent Entry

时间:2017-06-15 10:20:45

标签: sql

I have joined two tables

select * from prod 
inner join stock_inventory_new on prod.prod_cd=stock_inventory_new.prod_cd 

And I want to bring back only the latest entries for prod_cd, do I need to insert a MAX date?

1 个答案:

答案 0 :(得分:0)

This should be order by date as descending order and limit no of rows.

Mysql:-

select * from prod 
inner join stock_inventory_new on prod.prod_cd=stock_inventory_new.prod_cd 
order by [date] desc Limit 20

MS sql:-

select TOP 20 from prod inner join stock_inventory_new on 
prod.prod_cd=stock_inventory_new.prod_cd order by [date] desc