Okay so I have two tables, with many columns, but for illustration purposes I have a
and b
:
a: b:
+---+-----+ +---+------+-----+
|id |name | |id | a_id |size |
+---+-----+ +---+------+-----+
What I want is to SELECT * FROM a
and then for each a'
in a
I want to SELECT id FROM b WHERE a_id = a'.id
. But can I create a single curery such that the results becomes:
ab:
+---+-----+--------------------------------+
|id |name | b_idx_1, b_idx_2, ... b_idx_n |
+---+-----+--------------------------------+
I tried:
SELECT id, name, (SELECT id FROM b WHERE b.a_id = a.id) FROM a WHERE a.name LIKE 'Random Name'
But then I get an error, with the sub-query returning more than one row.