Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

MYSQL query 2 tables

Options
  • 16-12-2009 11:55am
    #1
    Registered Users Posts: 8,070 ✭✭✭


    I have 2 tables

    A - some numbers
    B - lots of numbers


    How do i render/print numbers from B that are NOT in A
    [so basically if A included unsubscribed users, and B includes all users, then i wanna print only opted in users]

    [PHP]$queryString5 = "SELECT register.mobile, sms.mobile FROM register, sms WHERE sms.mobile != register.mobile";[/PHP]

    that doesnt quite work.


Comments

  • Registered Users Posts: 515 ✭✭✭NeverSayDie


    As it happens, there's a "NOT IN" query in SQL that does exactly that, see here for info;
    http://www.techonthenet.com/sql/in.php

    Edit; you could alternatively use a LEFT JOIN;
    http://www.w3schools.com/sql/sql_join_left.asp


  • Registered Users Posts: 9,579 ✭✭✭Webmonkey


    As it happens, there's a "NOT IN" query in SQL that does exactly that, see here for info;
    http://www.techonthenet.com/sql/in.php

    Edit; you could alternatively use a LEFT JOIN;
    http://www.w3schools.com/sql/sql_join_left.asp
    Yup,

    A little example:
    Get a list of part names for which there is no current shipment
     
    SELECT name
    FROM parts
    WHERE pno NOT IN (SELECT pno
                          FROM shipments)
    


  • Registered Users Posts: 8,070 ✭✭✭Placebo


    thanks guys, found it earlier

    [PHP]$queryString5 = "SELECT register.mobile FROM register WHERE register.mobile NOT IN (SELECT sms.mobile FROM sms)";

    [/PHP]


  • Registered Users Posts: 2,781 ✭✭✭amen


    just a pet hate but you have no order by clause on your sql statement.

    drives me mad. Lead to inconsistent result orders from the same sp


  • Closed Accounts Posts: 2,696 ✭✭✭mark renton


    amen wrote: »
    just a pet hate but you have no order by clause on your sql statement.

    drives me mad. Lead to inconsistent result orders from the same sp

    :rolleyes:


  • Advertisement
  • Closed Accounts Posts: 910 ✭✭✭Jagera


    amen wrote: »
    just a pet hate but you have no order by clause on your sql statement.

    drives me mad. Lead to inconsistent result orders from the same sp

    There are multiple reasons why a sql query wouldn't need an ORDER BY.

    OP's query wasnt an sp either.


Advertisement