select distinct
page0.MatterType,
page0.Name,
page0.MatterNo,
page0.security,
page0.serial,
page6.TribCaseNo,
contact0.Name as Cname
from
page0, page6, page14
left join
contact0 on page0.PrimaryContact = contact0.linkserial
where
page0.serial = page6.CaseSerial
AND page0.serial = page14.CaseSerial
AND (page14.staffmember = '100001^24' and page14.status != 'Inactive')
AND page0.status != 'Closed'
我一直收到错误
多部分标识符page0.PrimaryContact无法绑定。
我检查了语法和拼写,两者似乎都是正确的。
谢谢!
答案 0 :(得分:6)
您需要进行显式连接。目前您正在使用旧的连接语法。考虑重构:
select P0.*, P6.TribCaseNo, C0.Name as Cname
FROM page0 AS P0
INNER JOIN page6 AS P6 on P0.serial = P6.CaseSerial
INNER JOIN page14 AS P14 ON P0.serial = P14.CaseSerial
LEFT JOIN contact0 AS C0 on P0.PrimaryContact = C0.linkserial
WHERE (P14.staffmember = '100001^24' AND P14.status != 'Inactive')
AND P0.status != 'Closed'
答案 1 :(得分:1)
您可以通过更改FROM
中的表格顺序来使查询工作:
select distinct
page0.MatterType,
page0.Name,
page0.MatterNo,
page0.security,
page0.serial,
page6.TribCaseNo,
contact0.Name as Cname
from
page6, page14, page0 --NOTE: page0 is now closest to join!!!
left join
contact0 on page0.PrimaryContact = contact0.linkserial
where
page0.serial = page6.CaseSerial
AND page0.serial = page14.CaseSerial
AND (page14.staffmember = '100001^24' and page14.status != 'Inactive')
AND page0.status != 'Closed'
<强>更新即可。
一般来说,我强烈建议你不要混合旧语法和新语法(就像在这里完成的那样), p.campbell 的解决方案是编写查询的正确方法。