General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 16th, 2003, 04:53 PM
zigote zigote is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Atlanta GA
Posts: 73 zigote User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 11 sec
Reputation Power: 7
Multiple Query w/ Count

I'm trying to query 2 tables,
List the details from one and count total rows from another where Id's are the same.

$dbQuery = "SELECT reviewId FROM dataReviews";
$dbQuery = "SELECT criticDataId FROM criticRating";

$totalCount = mysql_query("SELECT COUNT(*) AS count FROM criticRating WHERE criticDataId = '$reviewId' ");

Example:
-------------------------------------------
dataReviews table
reviewId <= primary key
1 | 2 | 3

criticRating table
criticDataId <= not primary key
2 | 3 | 2 |1 | 2

reviewId 1 has a total of 1
reviewId 2 has a total of 3
reviewId 3 has a total of 1
-------------------------------------------

I also tried something like this.

$queryDetails = "SELECT dataReviews.reviewId, criticRating.criticDataId FROM dataReviews, criticRating";

$totalCount = mysql_query("SELECT COUNT(*) AS count FROM criticRating.criticDataId WHERE criticReviewId = '$reviewId' ");

I hope someone can understand what I'm trying to do here.

Reply With Quote
  #2  
Old October 16th, 2003, 08:50 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
1. Are you trying to count the number of times each value in criticRating.criticDataId appears in the table

2. Would it be already known that the values in criticRating.criticDataId are the same values in dataReviews.reviewId or would they not be the same? (i.e. is criticRating.criticDataId the foreign key for dataReviews.reviewId?)
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #3  
Old October 17th, 2003, 12:41 AM
zigote zigote is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Atlanta GA
Posts: 73 zigote User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 11 sec
Reputation Power: 7
Yes laidbak,
I'm trying to count the number of times a dataReviews.reviewId appears in the table criticRating.criticDataId. They would be the same value.

I want to query dataReviews and then query criticRating and count how many times reviewId is in criticDataId.

So if I have a dataReviews.reviewId of "1"
and in criticRating.criticDataId there are 3 rows with the value of "1", then it would be "reviewId has 3 criticDataId counts".


dataReviews.reviewId is auto_increment and criticRating.criticDataId is just a updated int(11).

hope that helps. thnanks

Reply With Quote
  #4  
Old October 17th, 2003, 12:58 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
select criticDataId, count(criticDataId) As 'count' from criticRating GROUP BY criticDataId;

Reply With Quote
  #5  
Old October 17th, 2003, 08:52 AM
zigote zigote is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Atlanta GA
Posts: 73 zigote User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 11 sec
Reputation Power: 7
O.k that got me going in the right direction. Here's what I did to get the results back I needed.

$resultID = mysql_query("SELECT dataReviews.reviewId, criticRating.criticDataId, count(criticRating.criticDataId) As 'count' from criticRating, dataReviews WHERE dataReviews.reviewId = criticRating.criticDataId GROUP BY dataReviews.reviewId ");

Thanks Again! :-)

Reply With Quote
  #6  
Old October 17th, 2003, 10:52 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Ok, great.
I guess my only question would be why you need to include the table "dataReviews" in this query.

It seems all the data you need would be in the "criticRating" table.

Reply With Quote
  #7  
Old October 17th, 2003, 11:52 AM
zigote zigote is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Atlanta GA
Posts: 73 zigote User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 11 sec
Reputation Power: 7
The reason I have to include dataReviews.reviewId is to get the ID of the Review,

I have all information of a Item in dataReviews, And a few rating values in criticRating. I wanted to keep the data and rating separated, one reason is I also had a TIMESTAMP in dataReviews, which kelp going back to NOW() every time I rated.

I just moved all the rating to another table.

Over All looks something like.
Review ID | Title | Total Votes
1 | t1 | 3
2 | t2 | 4
3 | t3 | 6

This is my first time doing something like this, so there may be a easier way.

Reply With Quote
  #8  
Old October 17th, 2003, 05:16 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Yes, there are better ways to do it, however, one rule of thumb for programmers is "If it isn't broke don't fix it".

Reply With Quote
  #9  
Old October 17th, 2003, 10:56 PM
zigote zigote is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Atlanta GA
Posts: 73 zigote User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 55 m 11 sec
Reputation Power: 7
I do agree with you there...

Thanks again for all your help.

Reply With Quote
  #10  
Old October 18th, 2003, 12:43 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Anytime... take care.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Multiple Query w/ Count


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT