Reputation: 1435
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%");
Upvotes: 0
Views: 291
Reputation: 21
SELECT d.id, d.description, k.keywords
FROM documents d
JOIN documents_keywords dk
ON d.id = dk.document_id
JOIN keywords k
ON dk.keyword_id = k.id
WHERE (d.description LIKE '%certain%words%'
OR k.keywords LIKE '%certain%words%')
AND d.description NOT LIKE '%certain%other%words%'
AND k.keywords NOT LIKE '%certain%other%words%'
Upvotes: 2