In a MySQL SELECT statement, how can a derived field utilise the value of another field in the SELECT list?
For example, when running the following query:
SELECT
'tim' AS first_name
,first_name || ' example' AS full_name;
I would expect the result to be:
first_name, full_name
tim , tim example
Instead, I get the following error:
Unknown column 'first_name' in 'field list'.
Is there a way I can reference another column?
Thanks
Turgs
No, you have to repeat it or use a derived table.
select *, concat(first_name, ' example') as full_name
from (
select
'tim' as first_name ) as t
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