1

I have a question, I want to get counts of different tables in one query to show on a page...

This the query i wrote, But it's not providing correct result..

SELECT COUNT(U.uID) AS total, COUNT(P.cID) AS Catmame FROM `dev_web_user` AS U, `dev_web_categories` AS P

Please note all count is independent, now join etc...

Please help me on this...

Thanks & Best Regards,

DeDevelopers
  • 581
  • 1
  • 7
  • 25

2 Answers2

0

So try, this:

SELECT 
  (SELECT COUNT(U.uID) FROM `dev_web_user` AS U) as total,
  (SELECT COUNT(P.cID) FROM `dev_web_categories` AS P) as Catmame;
0

You can do this by joining them as two different temporary tables.

Try this way:

SELECT  * FROM
(SELECT COUNT(*) AS total FROM `dev_web_user`) T1 JOIN
(SELECT COUNT(*) AS Catmame FROM `dev_web_categories`) T2 ON 1=1

Sample Output:

TOTAL   CATMAME
4       8

See working demo in SQL Fiddle.

Raging Bull
  • 18,593
  • 13
  • 50
  • 55