将内部联接转换为左联接

时间:2016-02-08 09:50:19

标签: mysql ruby-on-rails ruby join

我有一个rake文件,我有这个代码。 。

   if circle[:conference2_total_channels].present?
                conf = Confbridge.find(:all, :conditions => ["confbridges.cid = ?",circle.circle_number],
                :joins => [:confbridge_participants],
                :select => 'confbridges.id, confbridges.confno, confbridges.max_member, (confbridges.max_member - 5) AS additional , (confbridges.max_member - IFNULL(confbridge_participants.active,0)) AS vacant')

            end

代码的返回是

SELECT confbridges.id, confbridges.confno, confbridges.max_member, (confbridges.max_member - 5) AS additional , (confbridges.max_member - IFNULL(confbridge_participants.active,0)) AS vacant FROM `confbridges` **INNER JOIN** `confbridge_participants` ON `confbridge_participants`.`confbridge_id` = `confbridges`.`id` WHERE (confbridges.cid = '0090000092')

INNER JOIN

如何将其更改为 LEFT JOIN

像这样

SELECT confbridges.id, confbridges.confno, confbridges.max_member, (confbridges.max_member - 5) AS additional , (confbridges.max_member - IFNULL(confbridge_participants.active,0)) AS vacant FROM `confbridges` **LEFT JOIN** `confbridge_participants` ON `confbridge_participants`.`confbridge_id` = `confbridges`.`id` WHERE (confbridges.cid = '0090000092')

谢谢:)

1 个答案:

答案 0 :(得分:0)

这就是我写它的方式:

<message>