Count same id column with different condition in same select statement
Asked By: Lekhulal Mathalipara
Originally Asked On: 2014-01-02 11:55:06
Asked Via: stackoverflow
I need to combine both select statements into one select
SELECT count(tbl_employer_post_details.employer_id) pending FROM tbl_employer_post_details, tbl_employer_registration WHERE job_status=0 AND tbl_employer_registration.employer_id = tbl_employer_post_details.employer_id LIMIT start,max;
And the second query, with the only difference being the
WHERE job_status=1
:SELECT count(tbl_employer_post_details.employer_id) approved FROM tbl_employer_post_details, tbl_employer_registration WHERE job_status=1 AND tbl_employer_registration.employer_id = tbl_employer_post_details.employer_id LIMIT start,max;
He received 4 answers
eventually accepting:
Saharsh Shah’s answer to
Count same id column with different condition in same select statement
Try this:
SELECT SUM(job_status = 0) pending, SUM(job_status = 1) approved FROM tbl_employer_post_details epd INNER JOIN tbl_employer_registration er ON epd.employer_id = er.employer_id WHERE job_status IN (0, 1);
The answer with the highest score with 1 points was:
Mihai’s answer to
Count same id column with different condition in same select statement
SELECT count(tbl_employer_post_details.employer_id) PostDetails FROM tbl_employer_post_details, tbl_employer_registration WHERE job_status IN(0,1) AND tbl_employer_registration.employer_id=tbl_employer_post_details.employer_id LIMIT start,max; SELECT SUM(job_status = 0) pending, SUM(job_status = 1) approved FROM tbl_employer_post_details, tbl_employer_registration WHERE job_status IN(0,1) AND tbl_employer_registration.employer_id=tbl_employer_post_details.employer_id LIMIT start,max;
If the selected answer did not help you out, the other answers might!
All Answers For: Count same id column with different condition in same select statement
Mihai’s answer to
Count same id column with different condition in same select statement
SELECT count(tbl_employer_post_details.employer_id) PostDetails FROM tbl_employer_post_details, tbl_employer_registration WHERE job_status IN(0,1) AND tbl_employer_registration.employer_id=tbl_employer_post_details.employer_id LIMIT start,max; SELECT SUM(job_status = 0) pending, SUM(job_status = 1) approved FROM tbl_employer_post_details, tbl_employer_registration WHERE job_status IN(0,1) AND tbl_employer_registration.employer_id=tbl_employer_post_details.employer_id LIMIT start,max;
peterm’s answer to
Count same id column with different condition in same select statement
Try it this way
SELECT SUM(job_status = 0) pending, SUM(job_status = 1) approved FROM tbl_employer_post_details d JOIN tbl_employer_registration r ON r.employer_id = d.employer_id WHERE job_status IN (0, 1)
Saharsh Shah’s answer to
Count same id column with different condition in same select statement
Try this:
SELECT SUM(job_status = 0) pending, SUM(job_status = 1) approved FROM tbl_employer_post_details epd INNER JOIN tbl_employer_registration er ON epd.employer_id = er.employer_id WHERE job_status IN (0, 1);
user2835274’s answer to
Count same id column with different condition in same select statement
Try it like this.
SELECT SUM(case when job_status = 0 then 1 else 0 end) pending, SUM(case when job_status = 1 then 1 else 0 end) approved FROM tbl_employer_post_details d JOIN tbl_employer_registration r ON r.employer_id = d.employer_id WHERE job_status IN (0, 1)
Of course, you should really check out the original question.
The post Count same id column with different condition in same select statement [ANSWERED] appeared first on Tech ABC to XYZ.