Author Topic: OR problem  (Read 1226 times)

0 Members and 1 Guest are viewing this topic.

Offline piznacTopic starter

  • Enthusiast
  • Posts: 282
    • View Profile
OR problem
« on: October 26, 2006, 10:55:34 AM »
hey guys,

Im having a problem that should be easy:

Code: [Select]
SELECT *
FROM subjob
WHERE pname = 'PHP Get Parameter'  AND subjob.markcomplate != 'Y' OR  subjob.markcomplate IS NULL


well I need this to give me the results filtered by the project name (pname) then filter it again by "markcomplete" not equaling 'Y'. But it would seem if that field is NULL then it won't return it. Strange but oh well,.. so I put in the OR statement and of course now its ignoring the first statement as long as that field is NULL,.. How would I do this correctly?
PHP Version 4.4.4
MySQL Version 4.1.21-standard
Apache Version 1.3.37(Unix)

Offline obsidian

  • Managed Insanity
  • Staff Alumni
  • Freak!
  • *
  • Posts: 6,440
  • Gender: Male
  • Talk to me, I won't bite... hard.
    • View Profile
    • Guahan Web
Re: OR problem
« Reply #1 on: October 26, 2006, 12:35:08 PM »
When dealing with AND and OR in the same query, you need to show precedence by using parenthesis around the parts of the query you want grouped:
Code: [Select]
SELECT * FROM subjob WHERE pname = 'PHP Get Parameter AND (subjob.markcomplete != 'Y' OR subjob.markcomplete IS NULL
You can't win, you can't lose, you can't break even... you can't even get out of the game.

Code: [Select]
<?php
while (count($life->getQuestions()) > 0)
{   
$life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

Offline piznacTopic starter

  • Enthusiast
  • Posts: 282
    • View Profile
Re: OR problem
« Reply #2 on: October 26, 2006, 12:54:07 PM »
AH HA,... knew it had to be something simple. Thanks much!
PHP Version 4.4.4
MySQL Version 4.1.21-standard
Apache Version 1.3.37(Unix)