I have a field in database in which i have stored comma seperated keywords like: abc, def, ghi, jkl
Then I am doing a query like: “SELECT * FROM tablename WHERE keywords_field LIKE %def%”;
I am doing a simple query like that but its not returning any result. How to do ? I have used * also instead of % but that is also giving any results. Is it due to the comma seperated keywords in database ?
So many-to-many… you’re suggesting he put… what? You dont want him to do a join, you dont want him to put CSV… what was the actual suggestion? I’m lost.
If the Keywords table exists (which would be the case if you wanted to limit keyword choices… otherwise the keywords table is redundant and irrelevant), you have to join to the keywords table…
list products along with their keywords for selected products –
SELECT p.prodcode
, p.descr
, p.price
, GROUP_CONCAT(pk.keywords) AS keywords
FROM product AS p
LEFT OUTER
JOIN productkeywords AS pk
ON pk.prodcode = p.prodcode
WHERE p.descr LIKE '%pants%'
GROUP
BY p.prodcode
find products which have a certain keyword –
SELECT p.prodcode
, p.descr
, p.price
FROM productkeywords AS pk
INNER
JOIN product AS p
ON p.prodcode = pk.prodcode
WHERE pk.keyword = 'sandal'
see? no keywords table is required in the queries, even though it exists for referential integrity of keywords
let me ask you this, when you create a persons table, do you extract all the first names and store them in a separate table, replacing them in the persons table with an id, just to avoid storing “john” and “mary” over and over instead of 42 and 63 over and over?