Jump to content


Photo

OR problem


  • Please log in to reply
2 replies to this topic

#1 piznac

piznac
  • Members
  • PipPipPip
  • Advanced Member
  • 261 posts

Posted 26 October 2006 - 02:55 PM

hey guys,

Im having a problem that should be easy:

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?

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 26 October 2006 - 04:35 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:
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.

<?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

#3 piznac

piznac
  • Members
  • PipPipPip
  • Advanced Member
  • 261 posts

Posted 26 October 2006 - 04:54 PM

AH HA,... knew it had to be something simple. Thanks much!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users