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: 
You want the disease(s) that have both symptom 14 and 15, right? So your disease has to be in the list of all diseases that have 14 as a symptom, *and* in the list of diseases that have 15 as a symptom.

That could be:

```
SELECT * 
FROM disease 
WHERE ID in (select disease_id from disease_symptoms where symptoms_id=14)
and ID in (select disease_id from disease_symptoms where symptoms_id=15)
order by probability DESC 

```

[Example in SQL Fiddle](http://www.sqlfiddle.com/#!9/fd234b5/5/0)
```
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.