0

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?

Mike Bonnell
  • 16,181
  • 3
  • 61
  • 77
Mr. Brooks
  • 33
  • 1
  • 8

1 Answers1

1

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.

Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78