Does somebody know if it’s possible with a single SQL statement to compare the values of multiple columns in one row of an MySQL database?
I want to select the lowest value from these columns.
I could do this with a loop within my PHP script, but this would mean that I need to do multiple database queries and each time compare the selected value with the previously selected value. However, preferrably I just want to do 1 query.
wow, that would be a very simple solution. thanks a lot!
one more question though: that statement would give me the actual lowest value right?
any idea how I could also retrieve the column name of the column containing this lowest value?
and does anybody know of a good resource site that offers a complete overview of possible SQL statements? 'cause I fond the tutorial at w3schools.com a bit limited.
If your columns arent named like col1 , col2 etc you can use
ELT(N,str1,str2,str3,…)
Returns str1 if N = 1, str2 if N = 2, and so on. Returns NULL if N is less than 1 or greater than the number of arguments. ELT() is the complement of FIELD():
I don’t think I understand all of that. :stunned:
I also found a chapter in the mysql.com reference manual about SQL syntax but I can’t find all the things that you use here. Are there things that I’m missing here??