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)
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.