Age Query - Additional Columns

I am using a bit of SQL from this thread: Calculate Age From Birthday to calculate the age in a query. It is working perfectly to calculate the age but I am having trouble adding additional columns to that query. I would like to at least add the “ID” column from the same table.

SELECT (1.0 * MYDATE / 365) AS AGE FROM (SELECT DATEDIFF( 'day', "BIRTHDATE", CURRENT_TIMESTAMP ) "MYDATE" FROM "BIRTHDATES")

In my basic knowledge of SQL I usually simply add a comma and the name of the next column that I would like to see in the query, but with this more complicated bit of code that includes parentheses, I haven’t been able to figure out the correct syntax.

Thank you!

Hello,

See no reason for a sub query here. This works using HSQLDB:

SELECT "ID", 1.0 * DATEDIFF( 'day', "BIRTHDATE", CURRENT_TIMESTAMP ) / 365 As AGE FROM "BIRTHDATES"

Using your statement it would be:

SELECT "ID", (1.0 * MYDATE / 365) AS AGE FROM (SELECT "ID", DATEDIFF( 'day', "BIRTHDATE", CURRENT_TIMESTAMP ) "MYDATE" FROM "BIRTHDATES")

Yes, understood it was my statement in the comments. However things change in almost 4 years. :slight_smile:

@Ratslinger this worked perfectly. Thank you!