No one pointed out the actual problem with the Bad code
so: You need to name the inner SELECT
's output using AS some_name
SELECT COUNT(ip_address) FROM (
SELECT DISTINCT ip_address FROM `ports` WHERE status IS TRUE
) AS some_name
As mentioned already, best is:
SELECT COUNT(DISTINCT ip_address) FROM `ports`;
Why?
On MySQL 5.7 you get ERROR "[42000][1248] Every derived table must have its own alias"
without AS some_name
. With it, it works.secs ago