Reputation: 9
i don't know if i'm not searching for this solution with the proper description of the problem, but i've not been able to find the answer for my situation.
Basically i have a table that i'm going to self join, so for that i use an Alias for this table (T1). In this table i have a datetime field and i want to extract only the year with the year function like this:
SELECT t1.item,
t1.quantity,
t1.time_in,
t1.YEAR(time_in) AS year
FROM rec AS t1
But i get the following error: FUNCTION t1.YEAR does not exist. Check the 'Function Name Parsing and Resolution' section in the Reference Manual
I tried to use backticks for the table alias like this 't1'.YEAR(time_in), but this didn't work either.
What am i doing wrong?
Thanks
Upvotes: 0
Views: 76
Reputation: 780871
Table names/aliases go before column names, not before functions.
SELECT t1.item,
t1.quantity,
t1.time_in,
YEAR(t1.time_in) AS year
FROM rec AS t1
Upvotes: 2