I'm a total postgresql noob...
I have 3 tables : Documents, Keywords and the join table Documents_Keywords
update
I want to select the id and description from Documents and the keywords from keywords where the description or the keywords are like "certain" and "words" and are not "certain" and "other" and "words".
end of update
The first try I gave to this was :
SELECT actes.id
FROM actes JOIN "actes_motclefs"
ON "motclefs"."id" = "actes_motclefs"."motclef_id"
WHERE ("motclefs"."motcle" LIKE "%éch%");
documentsandkeywordswhile a row inkeywordsstill can contain multiple words? Or you just want to search for word parts too?SELECT DISTINCT "documents"."id","documents"."document_date" FROM "documents" INNER JOIN "documents_keywords" ON "documents_keywords"."document_id" = "document"."id" INNER JOIN "keywords" ON "keywords"."id" = "documents_keywords"."keyword_id" WHERE (document_date BETWEEN '900' AND '1400') AND (keyword = 'prébende');I tried to make that last bitAND (keyword = 'prébende') AND (keyword = 'pagus')but that's not the way to do this.HAVING COUNT(keywords.id) = 2as I wrote. It will ensure, that only those documents will be returned, which have 2 matching keywords, each of which is eitherstoneORbrick(or in other words: both of them). -- OFC, it will only work, whenkeywordis unique inkeywordsand thedocuments_keywordsjunction table only contains unique relations. -- you could useHAVING COUNT(DISTINCT keyword) = 2otherwise.