I am trying to create a simple search based on tables 2 MySQL. One of the named keywords (words) and the other is called keyword2data (a map that associates words with a data source).
Keywords contain id and keyword whilst keywords2data contains keyword_id and data_id.
data_id is a link to the 3rd, but in this case non-essential table.
I want to be able to search, for example, "dog sled", and get all the data_id that are associated with these keywords.
SELECT k2d.`data_id` , k2d.`keyword_id`
FROM keywords2data as k2d, keywords as k
WHERE k2d.`keyword_id` = k.`id`
&& (k.`keyword` = 'dog' || k.`keyword` = 'sled')
LIMIT 10
Gives me all the data_id that has a dog or sled attached to it, not necessarily both what I want.
SELECT k2d.`data_id` , k2d.`keyword_id`
FROM keywords2data as k2d, keywords as k
WHERE k2d.`keyword_id` = k.`id`
&& (k.`keyword` = 'dog' && k.`keyword` = 'sled')
LIMIT 10
It does not give me anything, since not a single line in keywords2data contains 2 keywords.
What is the right way to do this?