我有两张桌子:
论坛:
+-----------+----------------+-----------------+-------------+---------------+
| forum_id |user_profile_id |profile_forum_id |profile_role |profile_status |
+-----------+----------------+-----------------+-------------+---------------+
| 9 | 7 | 2 | moderator | active |
| 10 | 1 | 2 | admin | active |
| 40 | 1 | 1 | admin | active |
+-----------+----------------+-----------------+-------------+---------------+
DDX:
+----+-----------+-------------+---------------+-----------------+
| id |profile_id |profile_name | DDX_content |profile_forum_id |
+----+-----------+-------------+---------------+-----------------+
| 2 | 1 | user1 | 874420 | 1 |
| 3 | 1 | user2 | 124500 | 2 |
+----+-----------+-------------+---------------+-----------------+
现在我想获得所有用户的列表(包含3列:profile_name,DDX_content,profile_role),其中包含' admin'或者'主持人'特定论坛ID的角色。我怎么能这样做?
答案 0 :(得分:0)
select ddx.profile_name, ddx.DDX_content, f.profile_role
from ddx
join forums f on f.user_profile_id = ddx.profile_id
where profile_role in ('admin','moderator')
and forum_id = 123
答案 1 :(得分:0)
尝试此请求:
SELECT
d.profile_name,
d.DDD_content,
f.profile_role
FROM
DDX AS d
INNER JOIN
Forums AS f
ON f.profile_forum_id = d.profile_forum_id
WHERE
(profile_role = 'admin' OR profile_role = 'moderator')
AND forum_id = 9;