mysql select update

Posted by Tillebeck on Stack Overflow See other posts from Stack Overflow or by Tillebeck
Published on 2010-03-23T11:12:18Z Indexed on 2010/03/23 11:13 UTC
Read the original article Hit count: 344

Filed under:
|
|
|

Got this:

Table a
ID RelatedBs
1  NULL
2  NULL

Table b
AID ID
1   1
1   2
1   3
2   4
2   5
2   6

Need Table a to have a comma separated list as given in table b. And then table b will become obsolete:

Table a
ID RelatedBs
1  1,2,3
2  4,5,6

This does not rund through all records, but just ad one 'b' to 'table a'

UPDATE a, b
SET relatedbs = CONCAT(relatedbs,',',b.id)
WHERE a.id = b.aid

© Stack Overflow or respective owner

Related posts about mysql

Related posts about update