If you want a single result set with the first row containing a list of all user
s from table_a
, and subsequent rows listing all id
s from table_b
(one per row), you could UNION
the two queries. However, you would have to cast the results to a common data type (presumably something like varchar
), and you would technically need to include a sort order field to guarantee that the users are in the first row.
SELECT values
FROM (select group_concat(user) as values, 1 as sort_order from table_b
UNION ALL
select CAST(id as varchar) as values, 2 as sort_order from table_a
) sq
ORDER BY sort_order
;
This will almost certainly be at least slightly slower than running the two queries separately. Not sure if that will matter, in your circumstance.
(Note: UNION
checks for and eliminates duplicate rows; UNION ALL
just combines all rows without checking. Since we don't need to worry about duplicates....)
users
fromtable_b
to be used in a different place once, Something like if first row has thegroup_concat
and all rows after it is about theid