Show lowest value in Mysql

Asked

Viewed 684 times

0

I’m making a BD that shows the lowest value between three options, each option represents a column. I want to take the smallest value of a line where it contains these three values.

  • 4

    Hello! Have you ever tried anything? Share it with us please =)

1 answer

1

Use the LEAST():

SELECT LEAST(1,2,3);

Upshot:

1

It will return the lowest value between the values inserted in the function.


In your case do:

SELECT LEAST(ColunaA, ColunaB, ColunaC) FROM Tabela

This way you will get the lowest value between the three tables of each row.

  • And if I need to know which column has the lowest value?

  • @Luanpedro You can use a CASE LEAST(a, b, c) WHEN a THEN 'a' WHEN b THEN 'b' ELSE 'c', something out there. Maybe there’s something that can do that automatically, but just researching.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.