Reputation: 1325
I have tbl1
which has field date
and time
.Suppose there's another table tbl2
with field date_time
.Now,I want to take data from date
& time
field of tbl1
,combine them and insert to date_time
field of tbl2
,in Y-m-d H:i:s
format or which ever format possible.Please some one help,inserting from one table to another isn't a problem but combining value of two field then inserting to another table is making me headache?
Upvotes: 0
Views: 328
Reputation: 774
INSERT INTO tbl2 (date_time)
SELECT CONCAT(`date`, ' ', `time`)
FROM tbl1
WHERE your_condition
Upvotes: 1
Reputation: 521
You should concatenate the date and time field from tbl1.
Something like this:
INSERT INTO tbl2 (datetime_field)
VALUES (SELECT CONCAT(date_filed, ' ', time_field)
FROM tbl1 WHERE pk_field = your_condition);
Notice: The sub-select must return only one result!
Upvotes: 1