I actually don't have any code yet to provide..but I can give you the data I am trying to manipulate.
I am working with a set of tags/keywords. Keywords can be related to another via the 'related_id' column.
So my table looks like:
keyword_tbl:
keyword_id | keyword | related_id
For this example, lets imagine the table is populated with the following entries
Entry 1:
keyword_id : 1
keyword: Marathons
related_id: 0
Entry 2:
keyword_id : 2
keyword: Boston
related_id: 1
As you can see, this entry of Boston, is related to Marathons via the related_id
I am working on giving the user the ability to search. If they search for an individual term, thats easy and not the question. However, if they search for "Boston Marathon," I now am having difficulty with the query.
SELECT * FROM keyword WHERE keyword LIKE "%boston%" OR keyword LIKE "%marathon%"
After this initial query, i'd like to compare the results, which would be the 2 entries I detailed above.
Id like to return only the term that is related to the other. In this case, Boston is the 'lowest' common denominator, and thus, I'd like to return it.
Imagine: Marathons -> Boston
Can this be done in a single query?
Thanks!
related_idofkeyword: Bostonis related tokeyword:Marathonsand not the other way around.