MySQL Forums
Forum List  »  Newbie

Problem with query
Posted by: Dawid Piek
Date: October 03, 2018 11:55AM

Hello. I'm just starting with MySQL. I think I know quite a lot comparing to my practice. However I have a trouble with one query.

I have two tables in database. Let's say that one of those is table of products.

|ID|Product.|
|1.|Product1|
|2.|Product2|
|3.|Product3|

The second one is table with different prices of this products.
|ID|ProductID|Price|
|1 |1........|20...|
|2 |1........|30...|
|3 |1........|35...|
|4 |1........|50...|
|5 |2........|10...|
|6 |2........|60...|
|7 |2........|5....|
|8 |3........|2....|
|..|.........|.....|

The problem is I don't know how to match each product to its lowest price and the second lowest price.
For example, the result of query should look like this:

|Product |Lowest price|Second lowest price|
|Product1|20..........|30.................|
|Product2|5...........|10.................|
|........|............|...................|

I will appreciate any help from you.

Options: ReplyQuote


Subject
Written By
Posted
Problem with query
October 03, 2018 11:55AM
October 03, 2018 03:13PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.