www.webdeveloper.com
Results 1 to 4 of 4

Thread: Multiple SQL Tables

  1. #1
    Join Date
    Aug 2005
    Posts
    31

    Multiple SQL Tables

    I am trying to pull data from a table (table A), but only want to pull the records where the same ID does not appear in a second table (table B).

    Is this possible? Table A contains a unique ID field, which is referenced in Table B, so this field can be used to find entries for the same person.

    I started with just pulling the info I wanted from one table:

    SELECT * FROM A WHERE (availability = 'All') AND (site = '" & site & "') OR (availability = '" & availability & "') AND (site = '" & site & "')"

    and now think I need an "AND B.ID field ....." But that is where I get lost!

    I'm sure this is a very simple piece of code!
    Thank you for any assistance you can provide!

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    Code:
    INSERT INTO B SELECT * FROM A WHERE A.ID (IS) NOT IN (SELECT ID FROM B)
    the syntax for IS NOT IN will vary based on your DBMS. try it in various forms (IS NOT IN, NOT IN, ETC)
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  3. #3
    Join Date
    Jun 2003
    Location
    Indiana, USA
    Posts
    1,138
    Or try,
    Code:
    SELECT * FROM A, B WHERE A.ID <> B.ID
    Chris.Martz.me
    Some things Man was never meant to know. For everything else, there's Google.

  4. #4
    Join Date
    Sep 2004
    Location
    Northeast, FL
    Posts
    332
    Code:
    SELECT
         *
    FROM
         Table1 A
    WHERE
         (SELECT COUNT(*) FROM Table2 B WHERE B.ID = A.ID) = 0

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles