SQL Statement WHERE clause -


i have 2 tables in database. 1 applicants, being programmedetail. in programmedetail, capture minimum required applicant. when applicant sign programme, tied programmeid.

however, when sql statement, using innerjoin , where clause, kept getting error.

programmedetail table sample data:

------------------------------------------- |  programmeid  |   programmerequirement  | ------------------------------------------- |   p01         |          20             | ------------------------------------------- 

applicant table sample data:

----------------------------------- |   applicantid  |   programmeid  | ----------------------------------- |    a001        |      p01       | ----------------------------------- |    a002        |      p01       | ----------------------------------- 

desired output:

------------------------------------------- |  programmeid  |   programmerequirement  | ------------------------------------------- |   p01         |          20             | ------------------------------------------- 

because there's 2 applicants p01 , minimum requirement 20 applicants. p01 retrieved.

here's i've tried:

select * programmedetail pd inner join applicant appl     on pd.programmeid = appl.programmeid count(appl.applicantid) < pd.programmerequirement 

error:

is invalid in having clause because not contained in either aggregate function or group clause.

try following, have tried mysql , works desired output. have added columns need in result.

select pd.programmeid        pd.programmerequirement programmedetail pd inner join applicant appl     on pd.programmeid = appl.programmeid group pd.programmeid having count(*) < 20 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -