Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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?



17.3k

Hi Denzyl,

9 tables, this is just a short example.



1.4k
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%


17.3k

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

Best to you for 2017.