MySQL Forums
Forum List  »  Newbie

Mysql: Add another column to a table based on matching an id to the second table where there are many matching rows
Posted by: surjit singh
Date: March 18, 2018 02:45PM

I am learning MySql. I have a table t1
fid
----
ax

kx

Also have a table t2
fid mid
------
ax bx

ax cx

Would like to change table t1 to
fid mid
--------
ax bx, cx

kx NULL

Here is what I tried

ALTER TABLE t1 ADD COLUMN mid text DEFAULT NULL;

update t1

LEFT JOIN t2 ON t1.fid = t2.fid

set t1.mid = t2.mid;

I get
fid mid
--------
ax bx

kx NULL

I would like to have
fid mid
--------
ax bx, cx

kx NULL

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.