Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get number of same id's where the item was found in mysql?

Let’s say I have table like this:

some_id date
1 2022-02-01
2 2022-02-02
3 2022-02-03
3 2022-02-04
3 2022-02-05
3 2022-02-06

I want to get the number of rows based on the id where the date was found?

I tried this but it’s not working:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

SELECT COUNT(id) FROM dates WHERE date = '2022-02-04'

Expected output should be 4 rows since there are 4 same id’s where the 2022-02-04 was found.

>Solution :

This should do the job:

SELECT COUNT(*) FROM tbl 
WHERE id IN (
 SELECT id FROM tbl WHERE `date`='2022-02-04'
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading