Welcome Guest, Not a member yet? Register   Sign In
Mutiple SQL count() from several tables
#1

[eluser]agartzia[/eluser]
Hi! I'm trying to get some data from my database (MySQL) and I've been wandernig without any clear solution. Here's the problem:

I want to extract some data from my users (SELECT name, address, mail) and some statistics about them. I would like to get the count() on their Private Messages, Posts and Logged times.

I'm trying something like this
Code:
SELECT name,
       address,
       mail,
      (SELECT count(*) FROM pm WHERE user = "102") as total_pm,
      (SELECT count(*) FROM posts WHERE user = "102") AS total_posts,
      (SELECT count(*) FROM login WHERE user = "102") as total_login
FROM users
WHERE id = "102"
LIMIT 1

Of course it isn't working at all.

There's a way to make it without making 3-extra queries for each user?

Thanks!


Messages In This Thread
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 12:57 AM
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 03:18 AM
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 03:56 AM
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 04:23 AM
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 04:26 AM
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 05:20 AM
Mutiple SQL count() from several tables - by El Forum - 02-08-2008, 08:34 PM
Mutiple SQL count() from several tables - by El Forum - 02-12-2008, 04:41 AM
Mutiple SQL count() from several tables - by El Forum - 03-25-2008, 05:04 AM
Mutiple SQL count() from several tables - by El Forum - 03-25-2008, 05:25 AM
Mutiple SQL count() from several tables - by El Forum - 03-25-2008, 05:38 AM
Mutiple SQL count() from several tables - by El Forum - 03-25-2008, 05:42 AM



Theme © iAndrew 2016 - Forum software by © MyBB