I am using multiple join query in Mysql,
Table A
IdA
name
Table B
idB
name
A_id
Is there a possible way to build request that returns idA name VIRTUAL_FIELD
VIRTUAL_FIELD contains all the IDs of table B referenced to table A ?
For example
Table A
IdA : 1
name : Bananas
Table B
idB : 1
name : I
A_id : 1
idB : 2
name : K
A_id : 1
idB : 3
name : D
A_id : 1
My request returns
IdA : 1
name : Bananas
VIRTUAL_FIELD : 1,2,3 or [1,2,3] etc..
Any help would be appreciated
SELECT A.IdA, A.name, GROUP_CONCAT(B.idB) as VIRTUAL_FIELD
from TABLE A INNER JOIN TABLE B
ON B.A_id=A.IdA GROUP BY A.IdA
use group concat and group by
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With