我有以下查询,即使我添加了不同的内容,它也会返回带有重复项的360条记录:
SELECT DISTINCT
leads.FirstName,
leads.LastName,
calls.callDate,
calls.callstatus,
calls.calllog,
calls.whoCalled,
notes.Notes,
notes.`TimeStamp`,
messages.sentDate,
messages.`subject`,
messages.greeting,
messages.message,
messages.toEmail,
messages.whoSent
FROM
leads
left JOIN calls ON calls.LeadID = leads.LeadID
right join notes on leads.LeadID = notes.LeadID
right join messages on leads.LeadID = messages.LeadID where leads.leadid = 208
select * from notes where leadid = 208
- 它有3条记录:
select * from messages where leadid = 208
它有15条记录
select * from calls where leadid = 208
它有8条记录
答案 0 :(得分:0)
修改where
子句以除去连接表的NULL值
WHERE calls.LeadID IS NOT NULL AND notes.LeadID IS NOT NULL AND
messages.LeadID IS NOT NULL AND leads.leadid = 208