• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

quick SQL question

zimu

Diamond Member
hey guys. quick question.

got 5 tables. each has a field called "status." status is downloading, uploading or done.

whats the easiest way i can return a count of the AGGREGATE "downloading" records, "uploading" records and "done" records?

i know there has to be some way to do this without 5 queries, each saying count(*) from tableA where status = 'downloading' + count(*) from tableB.....


any help?
 
(SELECT status AS TableAStatus, count(*) AS TableACount from TableA group by status)
UNION
(SELECT status AS TableBStatus, count(*) AS TableBCount from TableB group by status)
UNION
(SELECT status AS TableCStatus, count(*) AS TableCCount from TableC group by status)
UNION
(SELECT status AS TableDStatus, count(*) AS TableDCount from TableD group by status)
UNION
(SELECT status AS TableEStatus, count(*) AS TableECount from TableE group by status)
 
Try This:

SELECT COUNT(*) AS StatusCount, Status
FROM
(
SELECT Status FROM TableA
UNION ALL
SELECT Status FROM TableB
UNION ALL
SELECT Status FROM TableC
UNION ALL
SELECT Status FROM TableD
UNION ALL
SELECT Status FROM TableE
)
GROUP BY Status

What MrChad suggested will get you the counts but they'll be separated out by tables.
 
Back
Top