0

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
  • Testing in delphi, it crashes in my try except when it reaches the query's Open. Testing it in MS Access, i get error in From clause. Adding parenthesis and retesting it in MS ACCESS, i get syntax error in join operation. Commented Dec 14, 2010 at 19:12

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, thank you, as i stated in my comment above, i did try to get it to work in MS ACCESS, but failed as well.
You failed in Access? Were you using the QBE to write the SQL? If not, why not? It guarantees Access-compatible SQL, so it's a great way to get it working. And it saves a boatload of typing.
1

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

1 Comment

I guess MS ACCESS in particular about using parenthesis and i guess i needed inner joins verses plain ol joins <smile>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.