SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist jimday1982's Avatar
    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    562
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is this delete query possible?

    I thought this would be a pretty simple delete query, but it's turning out to be quite a problem.

    I have two tables, "cust_email" and "cust_lookup" and the two fields I'm working with are "order_id" and "number". I'm trying to delete every record in "cust_lookup" where the "order_id" in the "cust_lookup" table = the "order_id" in the cust_email table and where "number" = 'PROCESSING'. Your help is greatly appreciated.

    What I've tried so far is:

    mysql_query("DELETE FROM cust_lookup WHERE number = 'PROCESSING' AND cust_lookup.order_id=cust_email.order_id") or die(mysql_error());

    and

    mysql_query("DELETE FROM cust_lookup WHERE number = 'PROCESSING' AND cust_lookup.order_id IN (SELECT order_id FROM cust_email)") or die(mysql_error());

    Someone else tried to help here: http://www.sitepoint.com/forums/show...postid=1619356

    I always get an error similar to: You have an error in your SQL syntax near 'SELECT order_id FROM cust_email' at line 1

    Your help is appreciated.
    Jimmy Day
    Senior Systems Analyst
    Piedmont Healthcare Corporation

  2. #2
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    What version of MySQL are you using? Any version before 4.1 does not support subqueries...

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    try this --
    Code:
    delete cust_lookup
      from cust_lookup
         , cust_email
     where cust_lookup.order_id
         = cust_email.order_id
       and cust_lookup.number = 'PROCESSING'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

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