I did an INSERT INTO
of data from an import table into a new table I created which has general info about people, name, address, dob, age, sex, etc.
When I did the insert into my new tables, the import data didn't have age for the people, so I did the following after the INSERT INTO
:
UPDATE table_a set age = (SELECT timestampdiff(year, dob, curdate()) AS age);
which instantly gave me everyone's age and updated the column accordingly.
Now I want to know who's having a birthday based on current date:
SELECT name, dob FROM table_a WHERE DAYOFYEAR(dob) - DAYOFYEAR(CURDATE()) = 0;
My question is: How do I do an update based when their dob = current date?
This is what I tried:
UPDATE table_a set age = (SELECT timestampdiff(year, dob, curdate()) AS age WHERE DAYOFYEAR(dob) - DAYOFYEAR(CURDATE()) = 0);
This is the error I get:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE DAYOFYEAR(dob) - DAYOFYEAR(CURDATE()) = 0)' at line 1
I don't understand what I am doing wrong...
Running MySQL 5.6.25
Thank you in advance for any replies.