PDA

View Full Version : count Queries


celestine
12-08-2003, 02:48 AM
Hi all,

I want to combine 8 queries into 1 query for my script but I get really weird results.

This is my query:-
$qMain = "SELECT count(a.artist_id) as ArtistCount, count(b.aid) as AvatarCount, count(c.brid) as BrushCount,
count(d.bid) as ButtonCount, count(e.gid) as LayoutCount, count(f.pid) as PngCount, count(g.wid) as WallCount,
count(h.tid) as TempCount
FROM artist a, avatars b, brushes c, buttons d, graphics e, pngs f,
wallpapers g, templates h ";

I would write 8 seperate queries to count each but I wanted to know if its possible to just run 1 query to get the same result.

Running the above query in MySQL 4.0.15, it returns "40784351731200" for all the variables.

Can someone tell me where I had gone wrong? thanks.

raf
12-08-2003, 10:50 AM
Since you don't join the tables, i don't see why you would like to try to have the 8 counts in one query.

I don't think that the number of querys is the key issue. Besides that this doesn't seem to work, performance will probably be a lot better if you run 8 seperate.

The result you get could very well be the cartesian product (=the number off all possible combinations between each record of each table) or it could just be the highest number mySQL can work with or it could just be rubish.

celestine
12-09-2003, 07:12 AM
okay. thank you. :)