Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    May 2010
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts

    help with this query

    I can't figure it out.

    Let say I have table1 and table2.

    table1 has exam_number, exam_title fields, table2 has exam_number,exam_title fields

    Let say the values of the tables are

    Code:
    Table1
    exam_number,  exam_title
     2                      3
     2                      4
     2                      5
    
    Table2
    exam_number,  exam_title
     2                     3
     2                     5

    What I want to get is table1 row(exam_number,exam_title) values, that does not exist on table2 row. Meaning I should get 2,4 on table1,thanks..

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    It would be easier if you were to combine the two tables together and just add an extra field to represent whatever caused you to split it into two tables.

    You might want to read up on database normalization.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Regular Coder
    Join Date
    May 2010
    Posts
    224
    Thanks
    0
    Thanked 0 Times in 0 Posts
    For simplicity,I did not include all the fields of the two table, it has a purpose why it's like that..

  • #4
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    what have you tried?

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,652
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    Code:
    SELECT T1.* 
    FROM table1 AS T1
    LEFT JOIN table2 AS T2
    ON ( T1.exam_number = T2.exam_number AND T1.exam_title = T2.exam_title )
    WHERE T2.exam_number IS NULL
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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