Simple: I would like to count the number of rows from the sub-query. Note that status is whether the host is online or not.
Bad code
SELECT COUNT(ip_address) FROM `ports` (
SELECT DISTINCT ip_address FROM `ports` WHERE status IS TRUE
)
Explained
The first query, when run on its own returns this:
SELECT DISTINCT ip_address FROM `ports` WHERE status IS TRUE
ip_address
192.168.1.1
192.168.1.2
192.168.1.248
192.168.1.251
192.168.1.254
The second query run on its own returns this:
SELECT COUNT(ip_address) FROM `ports`
17
Question
I would like to know how to count that list of 5 IP addresses.
I have been looking online at possible solutions to this simple problem and just getting frustrated, so thought I'd ask the experts.