1

In my project, I have table IDCA and IDCB.

I cat query sql like:

$liId=99;
select name from  IDCA  where stId='$liId';

And the result is:

John
Stack
Shansa
Aliya
Stock

Then I set allName of IDCB with these values.

update IDCB set allName=(select name from  IDCA  where stId='$liId') where stId='$liId';

But it works fail. And error is:

ERROR 1242 (21000): Subquery returns more than 1 row

Actually, I want set allName='John,Stack,Shansa,Aliya,Stock'. So who can help me?

john
  • 55
  • 1
  • 7

1 Answers1

1

try to using GROUP_CONCAT()

update IDCB set allName=(
    select GROUP_CONCAT(name) 
    from  IDCA  
    where stId='$liId' GROUP BY stId)
where stId='$liId';
David Brossard
  • 13,584
  • 6
  • 55
  • 88
ferhado
  • 2,363
  • 2
  • 12
  • 35