

SELECT DISTINCT ip_address FROM `ports` WHERE status IS TRUEīut, as Julien has suggested, you can rewrite your query just like this: SELECT COUNT(DISTINCT ip_address) FROM `ports` WHERE status IS TRUE The complete query would look like this: SELECT COUNT(*) FROM ( I have the following query: SELECT SUM ( cost ) FROM ( SELECT s.cost FROM sandwiches AS s WHERE s.name 'Cheese Steak' ) UNION ( SELECT p. Every derived table must have its own alias Posted by: Daniel Falci Date: 07:10AM I have the following query : select count (op) from ( select webeventoatendimento.idweboperacao as op, webeventoatendimento. So, since the subquery in your case is SELECT DISTINCT ip_address FROM `ports` WHERE status IS TRUE I keep getting: 'Every derived table must have its own alias ' Help - SELECT isassignedto.id, employee.lastname, alldocuments.name FROM employee INNER JOIN isassignedto ON isassignedto.employeeid employee.id INNER JOIN ( SELECT FROM ( SELECT FROM (SELECT lead.id AS id, lead. It is also mandatory that each column of the derived table should have unique names. (In MySQL it is also mandatory to assign a name to a subquery of this kind (it is actually called a derived table), which is why you can see the AS some_name following it.) The way you have written it, MySQL interprets your script as two independent queries, that is why you are getting two result sets. Every derived table must have its own alias.

Useless without ORDER BY Problem: Since you are specifying a single value for idCAT, it does not make sense to ORDER BY idCAT. Belongs after WHERE and before LIMIT LIMIT. The subquery should immediately follow the FROM keyword. What is x The missing alias on the subquery Get rid of the subquery: SELECT FROM.
#MYSQL UNION EVERY DERIVED TABLE MUST HAVE ITS OWN ALIAS HOW TO#
To answer your immediate question, how to count rows of a subquery, the syntax is as follows: SELECT COUNT(*) FROM (subquery) AS some_name
