Help with Delphi 7, ADO, & MS Access SQL Statement

老子叫甜甜 提交于 2020-01-16 18:26:09

问题


I have three tables (in a MS Access Database 2000 file *.mdb)

Knowledge
id
question
answer

Knowledge_Keywords
id
knowledgeid
keywordsid

Keywords
id
keyword

Need to get all the keywords for a knowledge

Select distinct keyword from keywords KW
Join knowledge_keywords KKW on KKW.keywordid = KW.id
Join Knowledge K on K.id = KKW.knowledgeid
Where k.id = 10

of course 10 is a example, i actually use a parameter there

Where k.id = :AKnowId';

and fill it in in code

qry.Parameters.ParamByName('AKnowId').Value:= AKnowledgeId;

anyway, i think the SQL is qrong, any help would be greatly appreciated


回答1:


Get the SQL working properly within Access itself (make a query, try your SQL, see if it returns anything). THEN worry about Delphi.




回答2:


Solved it!

Select distinct keyword
from (keywords KW
inner Join knowledge_keywords KKW on KKW.keywordid = KW.id)
inner Join Knowledge K on K.id = KKW.knowledgeid
Where k.id = 10



来源:https://stackoverflow.com/questions/4443152/help-with-delphi-7-ado-ms-access-sql-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!