Imagine you have two tables
table: name table: keyword
id name nameId keyword
1 dude1 1 blue
2 dude2 1 tall
2 blue
2 short
My objective is that if you search for blue and tall the result would be:
name matches
dude1 2
dude2 1
I am also using PHP but I would like to do as much as I can with only MySQL.
Any ideas? Pointing me in the right direction would be nice.
You need to join both columns using
INNER JOIN(that’s it if you want only records that has atleast a match on the other table otherwise useLEFT JOIN) and link them withname.id = keyword.nameid. Use aggregate functionCOUNTand group them by their name.or
SQLFiddle Demo