title: joomla subquery Declaration
body: <p>DEar Friends i need help on declaring this query in joomla</p>
  
  <pre><code>SELECT * FROM (SELECT a.tire_id,
                          GROUP_CONCAT(DISTINCT a.width ORDER BY a.width) AS width, 
                          GROUP_CONCAT(DISTINCT a.aspectratio ORDER BY a.aspectratio) AS aspectratio,
                          GROUP_CONCAT(DISTINCT a.radialbias ORDER BY a.radialbias) AS radialbias,
                          GROUP_CONCAT(DISTINCT a.ring ORDER BY a.ring) AS ring
                          FROM  ofhmc_nikran_tire_detail a
                          WHERE %s
                      group  by a.tire_id ) b
                      inner join ofhmc_nikran_tire c on b.tire_id = c.id
                      where %s"
  </code></pre>
  
  <p>i coded this :</p>
  
  <pre><code>// Get a db connection.
      $db = JFactory::getDbo();        
      // Create a new query object.
      // $query = $db-&gt;getQuery(true);
      $tiretype_Query = 'AND (';
      foreach ($tiretype as $value) {
          $tiretype_Query .= "c.cat_id LIKE '%.$value.%' OR ";
          # code...
      }
      $tiretype_Query = ($tiretype_Query == 'AND (')?'':substr($tiretype_Query,0,strlen($tiretype_Query)-3).') ';
  
      $tirewidth_Query = 'AND (';
      foreach ($tirewidth as $value) {
          $tirewidth_Query .= 'a.width LIKE \'%'.$value.'%\' OR ';
          # code...
      }
      $tirewidth_Query = ($tirewidth_Query == 'AND (')?'':substr($tirewidth_Query,0,strlen($tirewidth_Query)-3).') ';
  
      $aspectratio_Query = 'AND (';
      foreach ($aspectratio as $value) {
          $aspectratio_Query .= ' a.aspectratio LIKE \'%'.$value.'%\' OR ';
          # code...
      }
      $aspectratio_Query = ($aspectratio_Query == 'AND (')?'':substr($aspectratio_Query,0,strlen($aspectratio_Query)-3).') ';
  
      $radialbias_Query = 'AND (';
      foreach ($radialbias as $value) {
          $radialbias_Query .= ' a.radialbias LIKE \'%'.$value.'%\' OR ';
          # code...
      }
      $radialbias_Query = ($radialbias_Query == 'AND (')?'':substr($radialbias_Query,0,strlen($radialbias_Query)-3).') ';
  
      $ring_Query = 'AND (';
      foreach ($ring as $value) {
          $ring_Query .= ' a.ring LIKE \'%'.$value.'%\' OR ';
          # code...
      }
      $ring_Query = ($ring_Query == 'AND (')?'':substr($ring_Query,0,strlen($ring_Query)-3).') ';
  
      $pattern_Query = 'AND (';
      foreach ($pattern as $value) {
          $pattern_Query .= ' c.pattern LIKE \'%'.$value.'%\' OR ';
          # code...
      }
      $pattern_Query = ($pattern_Query == 'AND (')?'':substr($pattern_Query,0,strlen($pattern_Query)-3).') ';
  
      $corrector = " 1 = 1 ";
  
      $ConcatQueryDetail = $corrector .' '.$tirewidth_Query.$aspectratio_Query.$radialbias_Query.$ring_Query;
      $ConcatQueryMaster = $corrector .' '.$tiretype_Query.$pattern_Query;
  
      $sql=sprintf("SELECT * FROM (SELECT a.tire_id,
                          GROUP_CONCAT(DISTINCT a.width ORDER BY a.width) AS width, 
                          GROUP_CONCAT(DISTINCT a.aspectratio ORDER BY a.aspectratio) AS aspectratio,
                          GROUP_CONCAT(DISTINCT a.radialbias ORDER BY a.radialbias) AS radialbias,
                          GROUP_CONCAT(DISTINCT a.ring ORDER BY a.ring) AS ring
                          FROM  ofhmc_nikran_tire_detail a
                          WHERE %s
                      group  by a.tire_id ) b
                      inner join ofhmc_nikran_tire c on b.tire_id = c.id
                      where %s",
                      mysql_real_escape_string($ConcatQueryDetail),
                      mysql_real_escape_string($ConcatQueryMaster));
      // $sql = str_replace("\", "", $sql);
      return($sql);
      // $db-&gt;setQuery($sql);
      // $results = $db-&gt;loadObjectList();
      // return $results;
  </code></pre>
  
  <p>but i still face with problem because joomla retrieve \ whith in \'%'.$value.'%\' and it makes my query wrong 
  plz help me on this</p>
  
  <p>i'm looking for a way to implement this query with jDatabaseClass
  THank YOU </p>