Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

MYSQL query 2 tables

  • 16-12-2009 11:55AM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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