I have two queries that I want to combine into one output, I can not use UNIOn, because they have a different number of columns.
ref table with fields id refid cellid cat all of which contain integers
Query 1: Finds the total number of rows for each unique cellid
SELECT cellid, COUNT(*) totalcount, cat FROM rel GROUP BY cellid
Query 2: search mode (most common value) cat for each unique cellid
SELECT cellid, cat FROM rel t GROUP BY cellid, cat HAVING cat = ( SELECT cat FROM rel WHERE cellid = t.cellid GROUP BY cat ORDER BY COUNT(*) DESC, cat LIMIT 1 )
To give an example of what I'm trying to do, I want to query a table
id | refid | cellid | cat 1 | 1 | 1 | 1 2 | 2 | 2 | 2 3 | 3 | 3 | 4 4 | 1 | 1 | 2 5 | 2 | 1 | 2 6 | 3 | 1 | 3 7 | 1 | 2 | 2 8 | 1 | 1 | 2
and return
cellid | no_of_rows | Mode_of_cat 1 | 5 | 2 2 | 2 | 2 3 | 1 | 4
falcs source share