Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>I would try to split the words using a regex and put them into a temporary table with wich you can join your Person table.</strong></p> <p>The regex might look something like this</p> <pre><code>preg_match_all('/(\S+)*\s+/im', $input, $value, PREG_PATTERN_ORDER); for ($i = 0; $i &lt; count($value[0]); $i++) { # Matched text = $result[0][$i]; } </code></pre> <p>a script that would find your results could look like this in SQL Server. <em>I don't have enough MySQL knowledge to come up with an alternative in MySQL but you should get the idea</em>. </p> <p>The gist of the idea is to join with the input table on every column you wish to search for. The <code>where</code> clause takes care of the fact that the input values are found in at least the amount of columns as there are input values. </p> <pre><code>DECLARE @Table TABLE (Name VARCHAR(20), Surname VARCHAR(20), Address VARCHAR(20), IDCard VARCHAR(20), Town VARCHAR(20), Street VARCHAR(20)) DECLARE @Inputs TABLE (Value VARCHAR(32)) INSERT INTO @Table VALUES ('Doe', 'John', 'Dontknow', 'Dontknow', 'US', 'Skate') INSERT INTO @Inputs VALUES ('%John%') INSERT INTO @Inputs VALUES ('%Doe%') INSERT INTO @Inputs VALUES ('%Skate%') SELECT t.* FROM @Table t LEFT OUTER JOIN @Inputs i_name ON t.Name LIKE i_name.Value LEFT OUTER JOIN @Inputs i_surname ON t.SurName LIKE i_surname.Value LEFT OUTER JOIN @Inputs i_address ON t.Address LIKE i_address.Value LEFT OUTER JOIN @Inputs i_idcard ON t.IDCard LIKE i_idcard.Value LEFT OUTER JOIN @Inputs i_town ON t.Town LIKE i_town.Value LEFT OUTER JOIN @Inputs i_street ON t.Street LIKE i_street.Value CROSS APPLY (SELECT inputCount = COUNT(*) FROM @Inputs) cnt WHERE cnt.inputCount &lt;= CASE WHEN i_name.Value IS NULL THEN 0 ELSE 1 END + CASE WHEN i_surname.Value IS NULL THEN 0 ELSE 1 END + CASE WHEN i_address.Value IS NULL THEN 0 ELSE 1 END + CASE WHEN i_idcard.Value IS NULL THEN 0 ELSE 1 END + CASE WHEN i_town.Value IS NULL THEN 0 ELSE 1 END + CASE WHEN i_street.Value IS NULL THEN 0 ELSE 1 END </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload