Results 1 to 8 of 8

Thread: SQL 'NOT IN' problems

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Location
    New Zealand
    Posts
    5

    SQL 'NOT IN' problems

    Hi all...

    I have to tables. One has a set of dates, the other a list of transactions. I want to be able to produce a set of dates which are not included in the transaction table based on an ID.

    I have tried this

    "SELECT date FROM SchoolDates NOT IN (SELECT date FROM Transactions WHERE ID='$id') ORDER BY date"

    i have tried various combinations of the above but none seem to work, i am using php and a mySQL db.

    can anyone help?

    Thanks

    Jamie

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    I don't think mySQL supports inner select queries like that (at least not yet)....
    You may need to do the inner select first, build the list of ID's then pass that back to the outter select ... but I could be wrong.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2001
    Location
    New Zealand
    Posts
    5
    thanks for your help

    my SQL isn't that strong, how would you do what you've suggested.

    thankyou...

    Jamie

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: SQL 'NOT IN' problems

    i dont know about mySQL, but for any other database your syntax is wrong, it should be:


    "SELECT date FROM SchoolDates WHERE date NOT IN (SELECT date FROM Transactions WHERE ID='$id') ORDER BY date"

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Find out your MySQL version, 4+ supports inner queries.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Does anyone here use MySQL 4? My host upgrade to it awhile ago, but a great number of their clients had problems getting scripts to run afterwards, so they degraded back to a 3 release.

    Has anyone else had problems with it?

    And as a side question, can I have MySQL 3 and 4 installed at the same time, and use them one at a time (for development and testing)?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Does anyone here use MySQL 4?
    I installed it on my new server. But that doesn't mean anything because I haven't written any scripts for it.
    My brother uses it though, I believe. And since my old server still runs 3, that means my scripts are perfectly compatible with both.

    And as a side question, can I have MySQL 3 and 4 installed at the same time, and use them one at a time (for development and testing)?
    Yes, but you need to set one to use a different port than the default (which is somewhere in the 4000 range I think). This means you can't use simply the hostname to connect ("localhost") but you also have to pass the port ("localhost:4999").
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Alright, thanks.
    My evil laugh has a squeak in it.

    kristopherwilson.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width