I want to retrieve the count of rows with a specific value, But this value depends on a query that must be done before using this result
The known variable is adId
, for example adId
is 32
So I want to get the value of the requestFrom
where adId = 32
Easy: $result = SELECT requestFrom FROM myTable WHERE adId = 32
Then I get the count:
SELECT COUNT(*) FROM myTable WHERE requestFrom = $result AND adId = $adId AND requestStatus = '1'
- I want to do this (get the count) in only one query
+----+--------+-------------+------+--------+
| id | userId | requestFrom | adId | status |
+----+--------+-------------+------+--------+
| 1 | 23 | 58 | 32 | 1 |
| 2 | 23 | 65 | 37 | 0 |
| 3 | 76 | 27 | 73 | 1 |
| 4 | 29 | 58 | 29 | 1 |