SQL query for fetching attributes of the current entity from a table magazine type


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
9 views
There is a table that stores attributes of entities, such as a product identifier, price and date of the last update. When you add new prices to the table, a row is inserted ('id-product', 'new price', 'add'). How to obtain a sample with current prices for all goods?
by | 9 views

2 Answers

0 like 0 dislike
select id, price, date_modified
from prices
where id, date_modified in (
select id, max(date_modified)
from prices
group by id
)
\r
And if you have Oracle, it is possible without explicit subquery:
\r
select distinct id, first_value(price) over (partition by id order by date_modified desc)
from prices
by
0 like 0 dislike
It is possible without a subquery:
\r
select id, price, date_modified from.
group by id
having date_modified = max(date_modified)
by

Related questions

0 like 0 dislike
1 answer
asked Apr 11, 2019 by studprogrammist
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
27,923 users