0

This query is not working

 SELECT CAST(o.total as SIGNED INTEGER) as yakk 
 FROM `order` o   
 WHERE yakk  = '51' ORDER BY `o`.`order_id` DESC  limit 0, 50 

it says yakk column is uknown while if I remove where clause it works and shows the column

tadman
  • 208,517
  • 23
  • 234
  • 262

1 Answers1

2

You can't use alias in where condition you must repeat the code (and if you cast to integer then use an int for compare)

SELECT CAST(o.total as SIGNED INTEGER) as yakk 
FROM `order` o   
WHERE CAST(o.total as SIGNED INTEGER)  = 51 ORDER BY `o`.`order_id` DESC  limit 0, 50 

The alias created for select are not available for where because the where condition is evaluted before the select clause

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107