You need to choose the most expensive medicine.

Select Назва, Ціна from Ліки where Ціна > all(Select Ціна from Ліки) 

Empty fields are displayed.

Spreadsheet Screenshot

  • by sabzh, you can make an index by price, sort and take the first. The second option is to first find the maximum price, then select the appropriate product. - teran
  • And my request is incorrect? - arakul
  • There are more options, with joins, etc., this can be found among the questions on the selection of the string with the maximum value. This is a fairly frequent task. - teran
  • Your request, I do not quite understand what dialect is written. If it is pure SQL, what is all ? Write it in the form of Select Назва, Ціна from Ліки where Ціна = (Select max(Ціна) from Ліки) and will work. I am not very familiar with MS Access dialect. - teran
  • one
    @arakul Your current request is looking for records whose price is not the biggest, but more than the biggest. Yes, do as in the comments above the price is equal to the maximum - Mike

2 answers 2

 SELECT Назва, Ціна FROM Ліки WHERE Ціна = (SELECT MAX(Ціна) FROM Ліки) 

    You can "ORDER BY Lim LIM 1" - get exactly what you want.

    • It is necessary through a subordinate request. - arakul
    • Select Nazva, Tsina from Liki where Code in (SELECT Code from Liki ORDER BY Tsina DESC LIMIT 1) - Alexander Prokoshev
    • one
      Jesus Christ, why do we need grouping, sorting order descending and LIMIT to search for fields with the maximum number. - Kryshtop
    • @Kryshtop There is no talk of grouping here. In general, this option has the right to life, especially since in certain cases it is faster than the subquery - Mike
    • Sorting*. i am sorry - Kryshtop