Query Two Tables

Posted on 2012-09-01
Last Modified: 2012-09-01
I have a database that has two tables.  One table contains the details of a shop order, ie... T-Shirt Size, T-Shirt Color, Quantities of each.
Each item is stored individually but the entire order has a reference number.

The second Table contains the shipping and postage info for the entire order and is associated by the reference number.

How do I query both tables at the same time to see if both tables have the same reference numbers and if table two does not have the reference number and associated info it will print out the reference number from table one?

So, in a nut shell... query both tables and compare if each have a specific reference number and give me a list of entries in table one that do not have a matching reference number in table 2.
Question by:rgranlund
    LVL 20

    Accepted Solution

    select distinct(table1.referencenumber) from table1 left join  table2 on table1.referencnumber=table2.referencenumber where table2.referencenumber is NULL
    LVL 7

    Author Comment

    Will that work if there is no reference number in table two at all?
    LVL 7

    Author Comment

    @ thehagman   Thanks !!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now