Here is a query I’m trying to write:
SELECT I.*,
IF(MAX(B.`amount`) != 0, MAX(B.`amount`), I.`start`) AS `current_bid`,
`current_bid` * 1.05 AS `min_bid`
...
I am getting the error “Unknown column ‘current_bid'”. I am assuming it is because I just created the current column in the line before. Is there anyway I can make this query work the way I want it to? I guess one way to get it to work would be to use two if statements that say basically the same thing, like this:
SELECT I.*,
IF(MAX(B.`amount`) != 0, MAX(B.`amount`), I.`start`) AS `current_bid`,
IF(MAX(B.`amount`) != 0, MAX(B.`amount`) * 1.05, I.`start` * 1.05) AS `min_id`
...
But that seems horribly inefficient.
Also, is there a way I can assign current without calculating MAX(B.amount) twice?
I’m pretty sure that nested queries get executed first, so that you can use their results. Whereas different columns in the same query are treated as concurrent, so you can’t make them dependent on each other.