你可以试试
SELECT p.*,
e.id
FROM purchasers p INNER JOIN
events e ON e.purchaser_id = p.id INNER JOIN
(
SELECT p.*
FROM purchasers p
WHERE p.id = '$id'
) Original ON p.organization = Original.organization
AND p.city = Original.city
AND p.state = Original.state
子选举
原件
将返回原始购买者,然后链接到
购买者
表由
组织、城市和州
编辑:
更改查询后,仍将返回重复项,但仅针对每个购买者注册的事件数。如果您想检索
独特的
买家名单,你不能用
事件ID
,所以你需要
SELECT p.*
FROM purchasers p INNER JOIN
(
SELECT p.*
FROM purchasers p
WHERE p.id = '$id'
) Original ON p.organization = Original.organization
AND p.city = Original.city
AND p.state = Original.state