Warning: fopen(graphic_design/files/thread-2607-1.txt) [function.fopen]: failed to open stream: Permission denied in /graphic_design/global.php on line 421
file NOT opened COUNT(*) with 2 tables -
PDA

View Full Version : COUNT(*) with 2 tables


Arch Stanton
01-14-2005, 03:34 PM
I am tracking banner clicks and views in 2 tables with the id of the banner and the date the view or click happened. I want to count the number of clicks and views in one query, because I'm lazy.

So this is what I tried:

SELECT COUNT(banner_views.*) AS `views`, COUNT(banner_clicks.*) AS `clicks` FROM banner_views,banner_clicks WHERE banner_views.bannerID='4' AND banner_clicks.bannerID='4';

I am gonna do it it 2 separate queries because I'm pretty sure it's the only way:

SELECT COUNT(*) AS `views` FROM banner_views WHERE banner_views.bannerID='4';

SELECT COUNT(*) AS `clicks` FROM banner_clicks WHERE banner_clicks.bannerID='4';

For future reference, is there another way to do this?

Octane
01-16-2005, 04:35 PM
there is no reason to actually join these for a simple query on statistics, as there is no relation between the stats. Any attempt to join these two would just slow things down ... you are better off doing it as 2 seperate queries ... in my opinion.

Arch Stanton
01-17-2005, 09:13 AM
I'm lazy, thats the only reason.

Thanks.