[thelist] Help Combining SQL Results
r937
rudy at r937.com
Thu Mar 5 12:49:16 CST 2009
first thing i noticed, jay, is that your GROUP BY is invalid
which, since you say the query runs, means that this can only be mysql
here's how you sum them --
SELECT id
, value
, MAX(c_fk_id) AS idunnowhich
, SUM(num_entries) AS total_entries
FROM (
SELECT a.id
, a.value
, a.c_fk_id
, COUNT(*) AS num_entries
FROM A AS a
GROUP
BY a.id
, a.value
UNION ALL -- clearly UNION ALL, not UNION
SELECT b.id
, b.value
, b.c_fk_id
, COUNT(*)
FROM B AS b
GROUP
BY b.id
, b.value
) AS u
GROUP
BY id
, value
;o)
More information about the thelist
mailing list