Mr. Brooks Mr. Brooks - 1 year ago 85
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download