0

我已经能够使用 CodeIgniter 使这段代码工作db->query,如下所示:

$sql =
 'SELECT mapping_code,zone_name,installation_name 
  FROM installations,appearances,zones 
  WHERE 
  installations.installation_id = zones.installation_fk_id 
  AND appearances.installation_fk_id =  installations.installation_id 
  AND appearances.zone_fk_id = zones.zone_id 
  AND
  appearances.barcode = ?
 ';

return $this->db->query($sql,array($barcode));

如果我使用 Active Record 类尝试此操作,“外观”表会引发“非唯一表”错误。

我需要同时出现在区域和安装表上。

我怎样才能做到这一点?

4

1 回答 1

0

如果您希望使用 ActiveRecord 类,请查看 $this->db->join()。现在你只是在使用与 ActiveRecord 完全无关的普通 SQL。

当通过 phpMyAdmin、Navicat 等 MySQL 客户端运行时,这是否有效?

于 2010-02-24T09:33:05.623 回答