PriteshP23 Posted August 27, 2013 Share Posted August 27, 2013 I would like to solve this query. Query: $sql = 'SELECT DISTINCT *, c.ci as c_i FROM `GSM_cellule` c '. 'LEFT JOIN '.$table_freq.' f ON(c.nidtint=f.nidtint) '. 'WHERE c.NAP_'.$site->ur().' =\'1\' '. $this->_in.' and '.$this->_inetatbdespec.' and '.$this->_inindus.' GROUP BY c.nidtint ORDER BY c.nidtint '; Error: SELECT DISTINCT *, c.ci as c_i FROM `GSM_cellule` c LEFT JOIN GSM_celluleterrain f ON(c.nidtint=f.nidtint) WHERE c.NAP_PA ='1' AND RIGHT(LEFT(c.`nidtnoeud`,10),2) IN ('U1','U8') and c.etat IN ('ED + ES') and GROUP BY c.nidtint ORDER BY c.nidtint Thanks in advanced. Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted August 27, 2013 Share Posted August 27, 2013 (edited) $this->_inindus is empty resulting in the syntax - and GROUP BY also, GROUP BY some_term performs an ORDER BY some_term (the query needs to get the same rows being grouped, adjacent to each other before it can consolidate them.). so, you don't need ORDER BY unless you want a different order than what the GROUP BY resulted in. Edited August 27, 2013 by mac_gyver Quote Link to comment Share on other sites More sharing options...
Solution PriteshP23 Posted August 27, 2013 Author Solution Share Posted August 27, 2013 Thanks a lot Guru..!! SELECT DISTINCT * , c.ci AS c_i FROM `GSM_cellule` c LEFT JOIN GSM_celluleterrain f ON ( c.nidtint = f.nidtint ) WHERE c.NAP_PA = '1' AND RIGHT( LEFT( c.`nidtnoeud` , 10 ) , 2 ) IN ( 'U1' ) AND c.etat IN ( 'ED + ES' ) GROUP BY c.nidtint ORDER BY c.nidtint LIMIT 0 , 30 Quote Link to comment Share on other sites More sharing options...
vinny42 Posted September 1, 2013 Share Posted September 1, 2013 Are you sure this works? Youre doing a DISTINCT * which means you are getting duplicate rows through a mistake in the query. de GROUP-BY is further evidence of this bevause you are not doing any aggregation. This is not good. What are you trying to achieve here? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.