-2
Personal hail, Here there’s an example that a guy here from the community posted and I’m trying to adapt my needs but an error arises:
#1248 - Every derived table must have its own alias
My query
SELECT
date_format(TABLE_2.data, '%d/%m/%Y %H:%i:%s') as DATA_2,
date_format(TABLE_1.data, '%d/%m/%Y %H:%i:%s') as DATA_1,
Anos,
Mes,
Dias,
Horas,
Minutos
FROM TABLE_1
INNER JOIN
(
SELECT
data,
TIMESTAMPDIFF(YEAR, data, TABLE_1.data) as Anos,
TIMESTAMPDIFF(MONTH, data + INTERVAL TIMESTAMPDIFF(YEAR, data, TABLE_1.data) YEAR , TABLE_1.data) AS Mes,
TIMESTAMPDIFF(DAY, data + INTERVAL TIMESTAMPDIFF(MONTH, data, TABLE_1.data) MONTH , TABLE_1.data) AS Dias,
TIMESTAMPDIFF(HOUR, data + INTERVAL TIMESTAMPDIFF(DAY, data, TABLE_1.data) DAY , TABLE_1.data) AS Horas,
TIMESTAMPDIFF(MINUTE, data + INTERVAL TIMESTAMPDIFF(HOUR, data, TABLE_1.data) HOUR , TABLE_1.data) AS Minutos
FROM TABLE_2
)
ON TABLE_2.id = TABLE_1.id
I need to do the same as the example only using 2 tables and with sum of hours and minutes.
Thank you in advance for your attention
Have you researched the error
Every derived table must have its own alias
? Try putting aalias
after the parentheses inINNER JOIN
. Ex.:tbl2
. And then onON
, refer toalias
servant.tbl2.id = TABLE_1.id
.– Thomas