I am using the following query
SELECT COALESCE(curr_bid, start_bid) AS `bid`, `lot`.*, (SELECT COUNT(id) from bid where lot_id=lot.id) as bids_count FROM `lot` LEFT JOIN (SELECT `lot_step`.`id`, `lot_step`.`lot_id`, max(amount) as curr_bid FROM `lot_step` GROUP BY `lot_step`.`lot_id`) `ls` ON lot.id = ls.lot_id WHERE ((`bid` >= '100') AND (`bid` <= '100000000'))
But I always get Unknown column 'bid' in 'where clause'
. Not sure how can this happen, because I specified the column after SELECT