I tried the following SQL on this example playground page from W3Schools.
SELECT CustomerID AS Id, CustomerName AS Customer
FROM Customers
WHERE Customer="Alfreds Futterkiste";
But I get No value given for one or more required parameters.
as response.
It works if I use CustomerName
instead of the alias.
Is this a fail of the playground test page or is it just not possible?
The WHERE
clause is evaluated before select. Hence the where clause is not aware of the aliases you used.
So you need to use the original column name:
SELECT CustomerID AS Id, CustomerName AS Customer
FROM Customers
WHERE CustomerName="Alfreds Futterkiste";
If you must use alias in the where clause, you may use subquery or CTE (an overkill and may result in slower query):
SELECT * from (
SELECT CustomerID AS Id, CustomerName AS Customer
FROM Customers
) t WHERE Customer = "Alfreds Futterkiste";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With