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. Link to comment https://forums.phpfreaks.com/topic/281595-group-by-order-by-in-same-query/ Share on other sites More sharing options...
mac_gyver Posted August 27, 2013 Share Posted August 27, 2013 $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. Link to comment https://forums.phpfreaks.com/topic/281595-group-by-order-by-in-same-query/#findComment-1446960 Share on other sites More sharing options...
PriteshP23 Posted August 27, 2013 Author 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 Link to comment https://forums.phpfreaks.com/topic/281595-group-by-order-by-in-same-query/#findComment-1446977 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? Link to comment https://forums.phpfreaks.com/topic/281595-group-by-order-by-in-same-query/#findComment-1447629 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.