Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old April 24th, 2008, 06:01 PM
xenoterracide xenoterracide is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: MI, USA
Posts: 64 xenoterracide User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 22 m 5 sec
Reputation Power: 2
Send a message via AIM to xenoterracide Send a message via MSN to xenoterracide Send a message via Yahoo to xenoterracide Send a message via Google Talk to xenoterracide
Testing a query

Code:
 SELECT tags.title,
        artist.name,
        statistics.rating,
        statistics.playcounter,
        statistics.percentage -- score
   FROM statistics -- tags -- artist
        INNER JOIN tags
                ON tags.url = statistics.url
        INNER JOIN artist
                ON artist.id = tags.artist
  WHERE  statistics.percentage >= 70 OR
         statistics.playcounter = 0
         AND
         (statistics.rating >= 6 OR
         statistics.rating = 0);


this is my query as it stands....

but results vary based on parenthesis.

I need to test whether it returns anything for rating < 6

I'd also like to know what the difference in records is between this and

Code:
  WHERE  (statistics.percentage >= 70 OR
         statistics.playcounter = 0)
         AND
         (statistics.rating >= 6 OR
         statistics.rating = 0);
__________________
A blog listing abandoned open source projects. http://maintainance-required.blogspot.com/

Reply With Quote
  #2  
Old April 25th, 2008, 07:07 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Dev Shed God 25th Plane (17000 - 17499 posts)
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 17,130 r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level)r937 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 3 Weeks 4 Days 13 h 13 m 52 sec
Reputation Power: 883
this --
Code:
WHERE statistics.percentage >= 70 OR
      statistics.playcounter = 0
      AND
      (statistics.rating >= 6 OR
      statistics.rating = 0);
is equivalent to this --
Code:
WHERE statistics.percentage >= 70  OR (
      statistics.playcounter = 0
      AND
      (statistics.rating >= 6 OR
      statistics.rating = 0) );
the reason is because ANDs take precedence over ORs

it's similar to the way multiplication takes precedence over addition

3 + 4 * ( 5 + 6 ) = 47

what i think you want is
Code:
WHERE (statistics.percentage >= 70 OR
      statistics.playcounter = 0)
      AND
      (statistics.rating >= 6 OR
      statistics.rating = 0);


( 3 + 4 ) * ( 5 + 6 ) = 77
__________________
r937.com | rudy.ca

Reply With Quote
  #3  
Old April 25th, 2008, 08:19 AM
xenoterracide xenoterracide is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: MI, USA
Posts: 64 xenoterracide User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 22 m 5 sec
Reputation Power: 2
Send a message via AIM to xenoterracide Send a message via MSN to xenoterracide Send a message via Yahoo to xenoterracide Send a message via Google Talk to xenoterracide
thanks for that. I didn't think to pull up information on 'order of operations'.

stilled like to be able to figure out how to query it.

I just need to make sure nothing with a rating of 2 or 4 matches.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > Testing a query


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 5 hosted by Hostway