• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Reply to: SQL Query help

Collapse

You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:

  • You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
  • You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
  • If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.

Previously on "SQL Query help"

Collapse

  • GrumpyContractor
    replied
    Originally posted by mudskipper View Post
    Left join where the join returns null is probably more efficient, but for a one off it matters not. Is it a one off?
    +1

    Spot on.

    Leave a comment:


  • BrilloPad
    replied
    Originally posted by darrylmg View Post
    ...and Oracle.
    Also, it should perform as good as the NOT IN with the NULL, that was mentioned.
    Put an index on the mobile number column in the second table if there's not already one there.
    Assuming its a non-clustered index, you should be careful whether you add indexes or not. For something with alot of inserts/updates and few index uses it might not be worthwhile.

    Leave a comment:


  • darrylmg
    replied
    Originally posted by TheFaQQer View Post
    NOT EXISTS would be more performant than NOT IN in MySQL.
    ...and Oracle.
    Also, it should perform as good as the NOT IN with the NULL, that was mentioned.
    Put an index on the mobile number column in the second table if there's not already one there.

    Leave a comment:


  • TheFaQQer
    replied
    Originally posted by minestrone View Post
    I think the answer is a NOT IN
    NOT EXISTS would be more performant than NOT IN in MySQL.

    Leave a comment:


  • computerguru
    replied
    Originally posted by mudskipper View Post
    Left join where the join returns null is probably more efficient, but for a one off it matters not. Is it a one off?
    +1

    Leave a comment:


  • mudskipper
    replied
    Left join where the join returns null is probably more efficient, but for a one off it matters not. Is it a one off?

    Leave a comment:


  • minestrone
    replied
    Great, that works a treat

    Leave a comment:


  • minestrone
    replied
    Originally posted by eek View Post
    select * from CUSTOMER where customerid not in (select customerid using the query you have)

    Its hackville and there will be more optimized versions of it but that will work as a one off...
    Cheers

    Leave a comment:


  • minestrone
    replied
    I think the answer is a NOT IN

    Leave a comment:


  • eek
    replied
    Originally posted by minestrone View Post
    Would anyone be able to advise on this, im not sure how to do what I want to do.

    I have a table CUSTOMER which contains 10,000 rows and has a column MOBILE_NUMBER

    I have an OUTGOING_SMS table which contains 3,500 rows and also has a column MOBILE_NUMBER

    I'm looking to find all the customers who have not had an SMS which should be 6,500

    I know how to find all the customer who have had an SMS, its a simple join but I'm not sure how to find the inverse.

    Any help would be fantastic. cheers

    DB, is MySQL.
    select * from CUSTOMER where customerid not in (select customerid using the query you have)

    Its hackville and there will be more optimized versions of it but that will work as a one off...

    Leave a comment:


  • minestrone
    started a topic SQL Query help

    SQL Query help

    Would anyone be able to advise on this, im not sure how to do what I want to do.

    I have a table CUSTOMER which contains 10,000 rows and has a column MOBILE_NUMBER

    I have an OUTGOING_SMS table which contains 3,500 rows and also has a column MOBILE_NUMBER

    I'm looking to find all the customers who have not had an SMS which should be 6,500

    I know how to find all the customer who have had an SMS, its a simple join but I'm not sure how to find the inverse.

    Any help would be fantastic. cheers

    DB, is MySQL.

Working...
X