We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Get the most similar records

Hi,

i have an array with data, which is stored in a database table field searchField

["John","BMW","Germany"]

Now i will search in different tables after these data

    SELECT user.name, cars.model, country.nation WHERE
    user.name LIKE %JOHN% OR 
    cars.model LIKE %BMW% OR 
    country.nation LIKE %Germany%;

What is the best way to realize this?

Thx

Do you have a single table or are they 3 tables?



59.9k

Hi Denzyl,

9 tables, this is just a short example.



2.5k
Accepted
answer

I will use joins. It go like this:

 SELECT  user.name, cars.model, country.nation
 JOIN cars ON cars.user_id = user.id
 JOIN country ON country.user_id = user.id
 WHERE
 user.name LIKE %JHON%  OR country.model LIKE %BMW% OR country.nation LIKE%Germany%


59.9k

i will reply asap, i have to check this next year :-)

Best to you for 2017.