Mr. Brooks Mr. Brooks - 5 months ago 37
MySQL Question

MySQL multiple query

I want to count records of query. The problem is that the query is not constant.

I write something like this, but this is only almost good

select count(*) from (select * from users);

where the select * from users is only example

I think something about this:

String query = "select * from users";
String queryCount = "select count(*) from (" + query + ")";

This is not correct as in mysql query they wrote an error like this:

ERROR 1248 (42000): Every derived table must have its own alias

What is the correct command for that?


Try this:

 select count(*) from (select * from users) as alias;

there needs to be some name for result set that is generated by the query in brackets.