I have two tables in my bank and I do the JOIN with them. One table is a list of people and the other list that person's characteristics. By logic there is only one person and each person can have several characteristics, so two tables. So when I do a join it appears the same person a few times only with its side feature. EX:
+-----+---------+----------------+
| ID | PESSOA | CARACTERÍSTICA |
+-----+---------+----------------+
| 1 | Carlos | Alto |
+-----+---------+----------------+
| 1 | Carlos | Divertido |
+-----+---------+----------------+
| 1 | Carlos | Inteligente |
+-----+---------+----------------+
| 2 | Iago | Baixo |
+-----+---------+----------------+
| 2 | Iago | Divertido |
+-----+---------+----------------+
| 2 | Iago | Esperto |
+-----+---------+----------------+
| 3 | Artur | Divertido |
+-----+---------+----------------+
| 3 | Artur | Inteligente |
+-----+---------+----------------+
If I do the following select I get an empty result:
SELECT
p.*, c.*
FROM
pessoas AS p LEFT JOIN perfil AS c ON p.pid = c.perfil_pessoa
WHERE
c.caracteristica = 'Divertido' AND c.caracteristica = 'Inteligente'
When actually I would like the following result:
+-----+---------+----------------+
| ID | PESSOA | CARACTERÍSTICA |
+-----+---------+----------------+
| 1 | Carlos | Alto |
+-----+---------+----------------+
| 1 | Carlos | Divertido |
+-----+---------+----------------+
| 1 | Carlos | Inteligente |
+-----+---------+----------------+
| 3 | Artur | Divertido |
+-----+---------+----------------+
| 3 | Artur | Inteligente |
+-----+---------+----------------+
That is, to result in every person being 'Fun' and 'Smart'.
If in the WHERE
clause of select
I use IN
or OR
the result is also not what I expect, for the given example, the select would return all the results, since all people have " Funny ":
+-----+---------+----------------+
| ID | PESSOA | CARACTERÍSTICA |
+-----+---------+----------------+
| 1 | Carlos | Alto |
+-----+---------+----------------+
| 1 | Carlos | Divertido |
+-----+---------+----------------+
| 1 | Carlos | Inteligente |
+-----+---------+----------------+
| 2 | Iago | Baixo |
+-----+---------+----------------+
| 2 | Iago | Divertido |
+-----+---------+----------------+
| 2 | Iago | Esperto |
+-----+---------+----------------+
| 3 | Artur | Divertido |
+-----+---------+----------------+
| 3 | Artur | Inteligente |
+-----+---------+----------------+
The intent is to build filters using the characteristics of people.