Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to get results based on similarities, the following will give you a result but I had to write all the combinations so in real case scenario you will need to have <code>n! + 1</code>* conditions.</p> <blockquote> <p><b>n!</b> stands for <i>"factorial"</i> and for example <b>3!</b> means <b>3 * 2 * 1 = 6</b><br/> and <b>+1</b> is for the whole match (3 in your case)</p> </blockquote> <pre><code>SELECT GROUP_CONCAT(`Name` SEPARATOR ' - ') AS 'Names', COUNT(*) AS 'matches', 1 AS '_Age',1 AS '_Work',1 AS '_Eyes' FROM `my_table` WHERE `Age`='young' OR `Work`='home' OR `Eyes`='blue' GROUP BY `Age`,`Work`,`Eyes` HAVING `matches` &gt; 1 UNION SELECT GROUP_CONCAT(`Name` SEPARATOR ' - ') AS 'Names', COUNT(*) AS 'matches', 1 AS '_Age',1 AS '_Work',0 AS '_Eyes' FROM `my_table` WHERE `Age`='young' OR `Work`='home' OR `Eyes`='blue' GROUP BY `Age`,`Work` HAVING `matches` &gt; 1 UNION SELECT GROUP_CONCAT(`Name` SEPARATOR ' - ') AS 'Names', COUNT(*) AS 'matches', 1 AS '_Age',0 AS '_Work',1 AS '_Eyes' FROM `my_table` WHERE `Age`='young' OR `Work`='home' OR `Eyes`='blue' GROUP BY `Age`,`Eyes` HAVING `matches` &gt; 1 UNION SELECT GROUP_CONCAT(`Name` SEPARATOR ' - ') AS 'Names', COUNT(*) AS 'matches', 0 AS '_Age',1 AS '_Work',1 AS '_Eyes' FROM `my_table` WHERE `Age`='young' OR `Work`='home' OR `Eyes`='blue' GROUP BY `Work`,`Eyes` HAVING `matches` &gt; 1 UNION SELECT GROUP_CONCAT(`Name` SEPARATOR ' - ') AS 'Names', COUNT(*) AS 'matches', 1 AS '_Age',0 AS '_Work',0 AS '_Eyes' FROM `my_table` WHERE `Age`='young' OR `Work`='home' OR `Eyes`='blue' GROUP BY `Age` HAVING `matches` &gt; 1 UNION SELECT GROUP_CONCAT(`Name` SEPARATOR ' - ') AS 'Names', COUNT(*) AS 'matches', 0 AS '_Age',1 AS '_Work',0 AS '_Eyes' FROM `my_table` WHERE `Age`='young' OR `Work`='home' OR `Eyes`='blue' GROUP BY `Work` HAVING `matches` &gt; 1 UNION SELECT GROUP_CONCAT(`Name` SEPARATOR ' - ') AS 'Names', COUNT(*) AS 'matches', 0 AS '_Age',0 AS '_Work',1 AS '_Eyes' FROM `my_table` WHERE `Age`='young' OR `Work`='home' OR `Eyes`='blue' GROUP BY `Eyes` HAVING `matches` &gt; 1 ORDER BY `_Age`+`_Work`+`_Eyes` DESC, `matches` DESC </code></pre> <p>And the result will be</p> <pre><code>| Names | matches | _Age | _Work | _Eyes | +-----------------------------+---------+------+-------+-------+ | Mike - Marie | 2 | 1 | 1 | 1 | | John - Mike - Marie | 3 | 1 | 1 | 0 | | Mike - Marie | 2 | 1 | 0 | 1 | | John - Irvin | 2 | 0 | 1 | 1 | | Mike - Marie | 2 | 0 | 1 | 1 | | John - Mike - Irvin - Marie | 4 | 0 | 1 | 0 | | John - Mike - Marie | 3 | 1 | 0 | 0 | | Mike - Marie | 2 | 0 | 0 | 1 | | John - Irvin | 2 | 0 | 0 | 1 | </code></pre> <p>This is not extremely practical but I don't know how you can get name combinations by any other approach.</p>
    singulars
    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