Question: In the beginning I'd like to mention, that I was trying to search for simillar problems but I didn't found the solution. I am doing my best to select disease from my database by typing in few id keys from sympthoms table. The relation between Disease and Sympthoms tables are many-to-many with connecting table disease\_symptoms which holds FK fields(disease\_id and symptoms\_id)

As I'm asking for just one ID it works fine:

```
SELECT * FROM disease JOIN disease_symptoms ON 
   disease.id=disease_symptoms.disease_id where 
   disease_symptoms.symptoms_id=14 ORDER BY 
   `disease`.`probability` DESC 

```

But as I'm trying to ask for more ID's it doesn't:

```
SELECT * FROM disease JOIN disease_symptoms ON 
    disease.id=disease_symptoms.disease_id where 
    disease_symptoms.symptoms_id=14 AND 
    disease_symptoms.symptoms_id=15 ORDER BY 
    `disease`.`probability` DESC 

```

(I am trying to select flu (id=1) from disease, it is related with sympthoms rised temperature (id 14) and cough (id 15)) Later I'd like to make checkbox list with sympthoms, which will return matching disease. (php/symfony).

Where am I making mistake?

Thank You in advance :)

Answer: 
Your WHERE condition will never return any data.

```
disease_symptoms.symptoms_id=14 AND disease_symptoms.symptoms_id=15 

```

symptoms\_id can't be 14 AND 15 at the same time.

Try the following instead.

```
disease_symptoms.symptoms_id IN (14, 15)

```

Ok, from your comment I've a better idea of what you're after. Try this,

```
SELECT * FROM disease d
  JOIN disease_symptoms ds1 ON d.id = ds1.disease_id
  JOIN disease_symptoms ds2 ON d.id = ds2.disease_id
 WHERE ds1.symptoms_id = 14
   AND ds2.symptoms_id = 15

```

By using aliases you can join the disease table to the diseasse\_symptoms table twice, once for each sympton you're interested in.
```
SELECT * FROM disease_symptoms
JOIN disease ON disease_symptoms.disease_id = disease.id
WHERE  disease_symptoms.symptoms_id IN (14, 15)
ORDER BY `disease`.`probability` DESC 

```

You just need to select the relation from an opposite direction. 
This will return all diseases which have the given symptoms.