Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 571
  • Last Modified:

Merge MySql fields of table with phpmyadmin and sql statement

Hellow all,

Is it possible to merge fields in a table to a new table? Let me describe the situation. I have an external sql dump that has a birthday table with 18000 birthday dates. Like this:

tablename: birthdays
field 1: id (int 10)
field 2: day (double)
field 3: month (double)
field 4: year (varchar 255)

a record would be like this

| id | day | month | year |
| 1  | 9     | 10      | 1981 |

I'd like to merge these fields (and the contents of the fields) with an sql statement (phpmyadmin) to this:

tablename: birthdays
field1: id (int 10)
field2: birthday (date)

a record would be like this

| id | birthday      |
| 1  | 1981-10-09 |

Can this be done? And how?

greetz,
walter
0
wal_toor
Asked:
wal_toor
  • 2
  • 2
1 Solution
 
burningmaceCommented:
Create a new column in your table called BirthdayNew.

UPDATE birthdays SET BirthdayNew = year + '-' + month + '-' + day

Then delete the old columns and rename BirthdayNew to whatever you want.
0
 
wal_toorAuthor Commented:
Hmm zero rows affected? Should this sql statement handle all the 12000 records?

greetz,
walter
0
 
burningmaceCommented:
Sorry, forgetting MySQL requires concat.

UPDATE birthdays SET birthdate = concat(year, '-', month, '-', day);

Remember that you need birthdate to be a VARCHAR column.
0
 
wal_toorAuthor Commented:
Great!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now