The Little Guy Posted March 25, 2009 Share Posted March 25, 2009 I thought that this would work... but it doesn't, I would like to get a total from both returned results, basically this should always return one row and one column. It should contain a number 0+. SELECT SUM((SELECT COUNT(m.id) FROM mailbox m WHERE m.status = '0') UNION (SELECT COUNT(f.id) FROM friends f WHERE f.acc = '0')) as total How could I fix it? Link to comment https://forums.phpfreaks.com/topic/151150-solved-sum-of-two-select-results/ Share on other sites More sharing options...
bluejay002 Posted March 26, 2009 Share Posted March 26, 2009 try this: SELECT SUM (totalTable.total) as total FROM ( SELECT COUNT(m.id) as total FROM mailbox m WHERE m.status = '0' UNION SELECT COUNT(f.id) as total FROM friends f WHERE f.acc = '0' ) as totalTable did this work? Jay, Link to comment https://forums.phpfreaks.com/topic/151150-solved-sum-of-two-select-results/#findComment-794182 Share on other sites More sharing options...
The Little Guy Posted March 26, 2009 Author Share Posted March 26, 2009 Thanks, Works! Link to comment https://forums.phpfreaks.com/topic/151150-solved-sum-of-two-select-results/#findComment-794233 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.