Skip to main content
fixing syntax error
Source Link
Kashyap
  • 149
  • 6

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?

See: https://stackoverflow.com/questions/3363918/mysql-error-1248-42000-every-derived-table-must-have-its-own-alias

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

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`;

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?

See: https://stackoverflow.com/questions/3363918/mysql-error-1248-42000-every-derived-table-must-have-its-own-alias

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

fixing syntax error
Source Link
Kashyap
  • 149
  • 6

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 `ports` (
    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`;

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 `ports` (
    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`;

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`;
Source Link
Kashyap
  • 149
  • 6

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 `ports` (
    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`;