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:
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'
)