我有2个MySQL表格;
portal.campaignAccount_Relations
:
+------------+----------+---------+
| relationID | campaign | account |
+------------+----------+---------+
| 1 | 1 | 1 |
| 2 | 2 | 1 |
| 3 | 4 | 1 |
| 4 | 3 | 2 |
+------------+----------+---------+
和portal.campaign_queue
:
+----+----------------------------+---------+
| id | title | deleted |
+----+----------------------------+---------+
| 1 | Lorem Ipsum Dolor Sit Amet | 0 |
| 2 | Lorem Ipsum Dolor Sit Amet | 0 |
| 3 | Lorem Ipsum Dolor Sit Amet | 1 |
| 4 | Lorem Ipsum Dolor Sit Amet | 0 |
+----+----------------------------+---------+
我想找到portal.campaignAccount_Relations
的所有行,其中portal.campaign_queue
的`deleted`字段为0
为关联的广告系列。
我是INNER JOIN MySQL函数的新手,无法找到对此类查询的支持。我试过了:
SELECT campaignAccount_Relations.campaign, campaignAccount_Relations.account
FROM campaignAccount_Relations
INNER JOIN campaign_queue
ON campaign_queue.deleted = 0 AND campaign_queue.id=campaignAccount_Relations.campaign
并获得了我想要的价值观。这是正确/最有效的方法吗?
答案 0 :(得分:1)
答案 1 :(得分:-1)
你应该开始尝试不同的东西,因为它是最好的学习方式。以下是我使用左连接的帮助:
SELECT * FROM portal.campaignAccount_Relations car
LEFT JOIN proal.campaign_que cq ON car.relationId = cq.id
WHERE cq.deleted=0
或者您可能需要以下内容,不确定哪个列是广告系列的关系列...
SELECT * FROM portal.campaignAccount_Relations car
LEFT JOIN proal.campaign_que cq ON car.campaign = cq.id
WHERE cq.deleted=0
来自mysql.com:
在MySQL中,JOIN,CROSS JOIN和INNER JOIN是语法等价物(它们可以相互替换)
我没有测试任何这些,所以你可能需要调整语法等...