Home > Software engineering >  MySQL unable to use WHERE and JOIN together
MySQL unable to use WHERE and JOIN together

Time:12-27

I have 2 tables consisting of Table 1 Person: age_id(PK) and treatment, Table 2 genders: age_id(FK) and age

SELECT COUNT(genders.gender_id) AS count, genders.gender
FROM genders JOIN Person on genders.gender_id = Person.gender 
WHERE Person.treatment = “Yes”
GROUP BY genders.gender;

I am trying to display the number of people according to gender that has received treatment using JOIN and WHERE but am faced with this error. The Treatment column consists of rows with either "Yes" or "No" but somehow the WHERE condition is not detecting it, what am I doing wrong?

CodePudding user response:

Try this :

SELECT COUNT(genders.gender_id) AS count, genders.gender
FROM genders JOIN Person on genders.gender_id = Person.gender 
WHERE Person.treatment = 'Yes'
GROUP BY genders.gender;

Use single quote instead of double quotes

Single quotes are for Strings Literals (date literals are also strings); Double quotes are for Database Identifiers;

  • Related