Author Topic: SQL Help required  (Read 559 times)

Offline CaronaBlog

  • Level 1
  • *
  • Posts: 2
  • Reputation: +0/-0
    • View Profile
SQL Help required
« on: September 22, 2008, 10:14:42 PM »
this is my current MySQL script for my game:

SELECT * FROM `research` WHERE `id` NOT IN (SELECT `research_id` FROM `research_done` WHERE `cid` = 1) AND `gold` < 999 AND `level` <= 1 AND `required` IN (SELECT `research_id` FROM `research_done` WHERE `cid` = 1)

but i want the last IN to only work when `required` is not NULL

any suggestions?

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: SQL Help required
« Reply #1 on: September 23, 2008, 06:44:48 AM »
Wouldn't that simply be:

SELECT * FROM `research` WHERE `id` NOT IN (SELECT `research_id` FROM `research_done` WHERE `cid` = 1) AND `gold` < 999 AND `level` <= 1 AND (`required` = NULL || `required` IN (SELECT `research_id` FROM `research_done` WHERE `cid` = 1));

Or you can change to `required` != NULL, depending upon what you want to achieve.
Idiocy - Never underestimate the power of stupid people in large groups.


 


SimplePortal 2.3.3 © 2008-2010, SimplePortal