The Row Holding the Maximum of a Certain Column

Nasza ocena:

5
Wyświetleń: 329
Komentarze: 0
Notatek.pl

Pobierz ten dokument za darmo

Podgląd dokumentu
The Row Holding the Maximum of a Certain Column - strona 1

Fragment notatki:

The Row Holding the Maximum of a Certain Column
Task: Find the number, dealer, and price of the most expensive article.
This is easily done with a subquery:
SELECT article, dealer, price
FROM shop
WHERE price=(SELECT MAX(price) FROM shop);
+---------+--------+-------+
| article | dealer | price |
+---------+--------+-------+
| 0004 | D | 19.95 |
+---------+--------+-------+
Other solutions are to use a LEFT JOIN or to sort all rows descending by price and get only the first
row using the MySQL-specific LIMIT clause:
SELECT s1.article, s1.dealer, s1.price
FROM shop s1
LEFT JOIN shop s2 ON s1.price ... zobacz całą notatkę



Komentarze użytkowników (0)

Zaloguj się, aby dodać komentarz