set @param1 = 0 ;
set @param2 = 0;
set @param3 = 2;
SELECT tab2.col1 ,
max(tab1.`col2`)
FROM tab1
JOIN tab2 ON tab1.`col1` = tab2.`col1
WHERE (tab1.col1 = @param1 OR @param1 = 0)
AND ( (@param3 = 0 AND tab1.col2 = 0)
OR (@param3 = 1 AND (tab1.col2 = 0 OR tab1.col2 = 1))
OR (@param3 = 2) )
AND (@param2 = 0
OR tab1.col3 IN (
SELECT tab3.col3
FROM tab3 ad
WHERE (tab3.col2 = @param2 OR @param2 = 0))) --AND tab2.col2 < @param4
AND tab2.col3 = 1 --AND tab2.col4 < @param5 --AND tab2.col4 > @param6
GROUP BY tab2.col1;
SELECT tab2.col1 ,
max(tab1.`col2`)
FROM tab1
JOIN tab2 ON tab1.`col1` = tab2.`col1
WHERE tab2.col3 = 1
GROUP BY tab2.col1;
If it is, then tab2 needs
| Subject | Views | Written By | Posted |
|---|---|---|---|
| Group by not using index | 922 | Matthew Moles | 03/02/2012 10:06AM |
| Re: Group by not using index | 428 | irek kordirko | 03/03/2012 05:22PM |
| Re: Group by not using index | 542 | Rick James | 03/04/2012 10:59PM |
| Re: Group by not using index | 479 | Matthew Moles | 03/05/2012 03:57AM |
Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.