S
S
Sergey Prishchenko2017-05-16 12:59:18
MySQL
Sergey Prishchenko, 2017-05-16 12:59:18

How to get the maximum price from another table?

There are 2 tables
items
id | name
history
id | item_id | price | date
How to get a table like
item_id | name | price (maximum price for this product in the entire table) | date

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2017-05-16
@jonkofee

SELECT items.id AS `item_id`, items.name AS `name`, MAX(history.price) AS `max_price`, history.date AS `date` WHERE history.item_id = items.id;

Looks like it, if I'm not mistaken

L
Leonid, 2017-05-16
@zzevaka

SELECT item_id, items.name, max_price, date
FROM items
JOIN (SELECT item_id, date, max(price) max_price FROM history GROUP BY 1,2) t1
ON items.id = item_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question