List:General Discussion« Previous MessageNext Message »
From:Alex croes Date:December 6 2004 7:15pm
Subject:[sql]There was to be a simpeler way
View as plain text  
I'm currently using the following query:


SELECT  SUM(IF(`01`=1, 1,0)) AS 01A, SUM(IF(`01`=2, 2, 0)) AS 01B..., 
SUM(IF(`55`=1, 1,0)) AS 55A, SUM(IF(`55`=2, 1,0)) AS 55B FROM tableA 
INNER JOIN tableB ON tableA_ID = tableB_ID INNER JOIN tableCON 
tableB_aID = tableC_aID INNER JOIN tableD ON tableD_ID =tableC_ID INNER 
JOIN tableE ON tableD_ID = tableE_ID GROUP BY tableA_ID

The result has to the following. There mutiple rows of tableA_ID, if one 
of the fields 01 in this set has a 0 the result of the group by has to 
be 0. If one of the result has no 0 but a 1, the result of the group by 
has to be 1 and finally if  there is a 2 in the result, the group by has 
to be a 2.

I'm currently using the query as showned above, and another query to 
examing the results of above the get the right value. But there has to 
be a more efficient way (I hope). Can anybody here show me the better way.

TIA

AC


Thread
[sql]There was to be a simpeler wayAlex croes6 Dec