GatewayBit
GatewayBit

Reputation: 33

MySQL Alias Help ERROR 1054 (42S22)

I will keep this brief and simple. I want to perform this query:

mysql> SELECT ORDER_NUM, NUM_ORDERED * QUOTED_PRICE AS TOTAL_AMOUNT
    -> FROM ORDER_LINE
    -> WHERE TOTAL_AMOUNT > '1000'
    -> ORDER BY ORDER_NUM;
ERROR 1054 (42S22): Unknown column 'TOTAL_AMOUNT' in 'where clause'

I'm sure it's something simple but I don't understand why this wont work using the alias TOTAL_AMOUNT. Any help is appreciated!

Upvotes: 2

Views: 314

Answers (2)

PachinSV
PachinSV

Reputation: 3780

Check if that asterisk is not causing you problems or if you are missing a comma and if that does not work, enclose the alias between grave accent simbols like this:

... QUOTED_PRICE AS `TOTAL_AMOUNT`...

Upvotes: 0

echo_Me
echo_Me

Reputation: 37233

try this

mysql> SELECT ORDER_NUM, NUM_ORDERED * QUOTED_PRICE AS TOTAL_AMOUNT
-> FROM ORDER_LINE
-> WHERE NUM_ORDERED * QUOTED_PRICE > '1000'
-> ORDER BY ORDER_NUM;

Upvotes: 1

Related Questions