N
N
neyronius2010-12-06 11:01:39
SQL
neyronius, 2010-12-06 11:01:39

SQL query to select the current attributes of an entity from a log type table

There is a table where entity attributes are stored, for example, the product ID, its price and the date of the last update. When adding a new price, a row ('item-id', 'new price', 'time of adding') is inserted into the table. How to get a selection with current prices for all products?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
inittab, 2010-12-06
@neyronius

select id, price, date_modified
from prices where id ,
date_modified in ( select id, max (
date_modified)
from prices
group by id
) by id order by date_modified desc) from prices

A
ArtInt, 2010-12-06
@ArtInt

It is possible without a subquery:
select id, price, date_modified from prices
group by id
having date_modified = max(date_modified)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question