Jump to content
  • Advertisement
Sign in to follow this  
supagu

[web] [SQL] select - not in problem

This topic is 4441 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ive got the following SQL command: SELECT * FROM `uvtoolslicence` WHERE orderid NOT IN (SELECT id FROM orderform) which doesnt work when i run it in php my admin. SELECT id FROM orderform -works by itself, currently returns a null set SELECT * FROM `uvtoolslicence` -also works by itself, returns 1 row, as i only have 1 row in my table. any ideas why this may be failing, this is the error message i get:
#1064 - You have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT id FROM orderform )
LIMIT 0, 30' at line 1 

Share this post


Link to post
Share on other sites
Advertisement
my web provider is runnig version:
4.0.27-standard

if this is actually the problem, is there a work around?

Share this post


Link to post
Share on other sites
You are running an ancient and decrepid version of MySQL.

MySQL has had support for subqueries since 4.1, which was released quite a long time ago now.

A work-around is to use an outer join with a WHERE clause include WHERE somejoinedcolumn IS NULL.

The outer join will select all rows from the first table and join with rows from the second table where applicable, substituting NULL where there aren't any - we then select those rows with WHERE secondtable.id IS NULL (normally this ID can't be NULL, but it will be in an outer join).

As a bonus this method *may* perform better on large data sets even in databases which do support subqueries.

Mark

Share this post


Link to post
Share on other sites
Something like this (adjust for syntax where necessary):

SELECT * FROM `uvtoolslicence` LEFT JOIN orderform ON uvtoolslicence.orderid = orderform.id WHERE orderform.id = NULL


EDIT: Too slow! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!