如何用多行父查询单行返回编写子查询子查询

时间:2017-09-01 12:49:15

标签: php mysql codeigniter

以下查询会产生一些错误:

$sub = '( SELECT mulitple.* FROM timezoneabbreviation AS mulitple
      WHERE single.gmtoffset = mulitple.gmtoffset) AS sametimezone';
$query = "SELECT $sub,single.* FROM timezoneabbreviation AS single 
         WHERE full_name='".$full_name."' ";
return $this->db->query($query)->row(); 

我想在同一个表中使用子查询编写一个查询,其中条件主查询生成单行但子查询生成多行。

1 个答案:

答案 0 :(得分:0)

只需使用JOIN

即可
$query = "SELECT mulitple.*, single.*
          FROM timezoneabbreviation AS single
          INNER JOIN timezoneabbreviation AS mulitple
              ON mulitple.gmtoffset = single.gmtoffset
          WHERE single.full_name='".$full_name."'";