如何使用mysql选择内连接?

前端之家收集整理的这篇文章主要介绍了如何使用mysql选择内连接?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我想在以下条件下从mysql数据库获取记录

我有以下表格:

> organization_表

organizationId | organizationname

>活动表

camp_id | camp_name | adv_id | organizationId

>广告表

adv_id | adv_name

> ad_display表

ad_displayId | adv_id | camp_id |

现在从ad_display表我想要获取这样的记录:

| adv_name | camp_name | organizationname

使用WHERE Con​​dtion作为organizationId ==?

所以基本上我想要广告列表的campaign_id =?

Note: there should be multiple entry for same adv_id in camapign table and same camp_id with multiple entry in ad_display

最佳答案
试试这个:

SELECT ad.ad_displayId,a.adv_name,c.camp_name,o.organizationname 
FROM ad_display ad 
INNER JOIN advertise a ON ad.adv_id = a.adv_id 
INNER JOIN campaign c ON ad.camp_id = c.camp_id 
INNER JOIN organization o ON c.organizationId = o.organizationId 
WHERE o.organizationId = ?;

猜你在找的MySQL相关文章