Neveen
Neveen

Reputation: 2175

mysql - fill field by other fields

I have a birthdate, year, month, day columns where columns "year,month,day" are foreign key to other tables
What I want to do is for each birthdate get id(year(birthdate)) to be the value of year column and the same thing for month and day columns.

How can I do this in MySQL?

Thanks in advance

Upvotes: 0

Views: 610

Answers (3)

Gratzy
Gratzy

Reputation: 9389

Update mytable
set birthdate = Yearfield + monthfield + dayfield

EDIT

If birthdate is a date field you will have to cast or convert it first.

Update mytable
    set birthdate = Cast(Yearfield + monthfield + dayfield as date)

Upvotes: 2

Manrico Corazzi
Manrico Corazzi

Reputation: 11371

Try

update tableName set birthdate = month + "/" + day + "/" + year;

Upvotes: 0

pedromarce
pedromarce

Reputation: 5669

Check out triggers (http://dev.mysql.com/doc/refman/5.0/en/triggers.html) so every time the data is written you calculate and update the information you require.

Upvotes: 2

Related Questions