I can’t figure out how to count results from my query because I limit the output:
(SELECT "new" as type, name FROM newUsers WHERE name LIKE '%John%')
UNION
(SELECT "old" as type, name FROM oldUsers WHERE name LIKE '%John%')
ORDER BY 1 ASC LIMIT 1, 10
The farthest I got was to do SELECT COUNT(*) ( my query ) as userCount but then I don’t get all other fields that were outputted by my query.
This would probably answer the letter of what you seem to be asking for, but isn’t a very sensible way to formulate the query:
The only oddity here is that there is no join condition (neither an ON nor a USING clause) between the two tables. You might need to use a CROSS JOIN instead of an (INNER) JOIN; alternatively, you can introduce a column
"new" AS typeto the count query, and joinON n.type = c.type. You might then need to add a GROUP BY clause – in most DBMS you would need it, but MySQL may let you get away without it.However, I think you would do better with two separate queries – one for the type and name as in your question, and the other as:
Given that you are using MySQL, you may be able to get away without the GROUP BY clauses in the second query.