You could use a subquery (assuming MySQL 4.1):
[tt]
SELECT SUM(col1)
FROM
(
SELECT col1 FROM table WHERE col3 = 'value 1'
UNION ALL
SELECT col2 FROM table WHERE col4 = 'value 1'
)
u
[/tt]
or, a bit more exotic, and possibly slower, but works on earlier versions:
[tt]
SELECT SUM(col1*(col3='value 1')+col2*(col4='value 1'))
FROM table
[/tt]
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.