如何在同一查询中使用INNER JOIN和IN子句

时间:2016-06-18 11:40:53

标签: php mysql

我有三个表,想要对它们运行INNER JOIN和IN子句。 任何人都可以告诉我我在哪里做错了

    SELECT `tblinvoices`.id,`tblinvoices`.userid,`firstname`,`lastname`
            FROM `tblinvoices`
WHERE `paymentmethod`IN 
(SELECT  `gateway` FROM  `tblpaymentgateways` WHERE  `setting`='type' AND `value` = 'CC') 
INNER JOIN `tblclients` ON `tblinvoices`.userid=`tblclients`.id"

1 个答案:

答案 0 :(得分:4)

JOIN来自WHERE:

SELECT     tblinvoices.id,
           tblinvoices.userid,
           firstname,
           lastname
FROM       
           tblinvoices

INNER JOIN tblclients
        ON tblinvoices.userid = tblclients.id
WHERE      
      paymentmethod IN
           (select gateway
            FROM   tblpaymentgateways
            WHERE  setting='type'
             AND   value = 'CC')