我们需要更多信息!
这听起来像是基于搜索的查询包含两个表中具有一对多关系(即客户端和“客户端程序”)的列,使得单个客户端具有零至四个程序。
这听起来像你只想返回提供者列表(即一侧的行),但你的SQL从两个表中返回数据。
这里就是你的SQL可能需要的样子做你需要的东西:
SELECT *
FROM clients AS mainClient
WHERE
EXISTS
(SELECT 1
FROM clients AS C
LEFT JOIN ClientPrograms AS CP
ON C.ID = CP.ClientID
WHERE mainClient.ID = C.ID
' the above line links the EXISTS "Sub query" to the main query
AND client name like "*j*" ... etc...
... ie lots of criteria generated by you popup search criteria dialogue)
)
通过添加EXISTS语句中的主查询将可编辑。
如果你曾经使用SQL类似下面的你就不能编辑它
SELECT c.name, c.dob, etc.. ie all the field you want on the form whichwill all be from the client table
FROM clients AS C
LEFT JOIN ClientPrograms AS CP
ON C.ID = CP.ClientID
WHERE mainClient.ID = C.ID
' the above line links the EXISTS "Sub query" to the main query
AND client name like "*j*" ... etc...
... ie lots of criteria generated by you popup search criteria dialogue)
GROUP BY all the field in the select statement
我希望这给你一些启示
谢谢你这么多的灵感。我会破解并报告回来。非常感谢, –
你是否得到它的工作?如果是这样,你可以标记我的答案作为答案,向上箭头它... ...。 – HarveyFrench
您是否觉得上述有用?如果是这样,请举出答案。 – HarveyFrench