我們需要更多信息!
這聽起來像是基於搜索的查詢包含兩個表中具有一對多關係(即客戶端和「客戶端程序」)的列,使得單個客戶端具有零至四個程序。
這聽起來像你只想返回提供者列表(即一側的行),但你的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