locked
Getting data from two tables RRS feed

  • Question

  •  

    Hi,

     

    THis is my first ever post to a forum.

     

    My question is i have two tables one has all data and second has some data out of that table , now i want the data that is in the first table but not in the second table.

     

    Thanks in anticipation.

     

    Sunday, December 7, 2008 9:08 PM

Answers

  • Matka,

     

    Welcome to the MSDN Forums.  Since this is your first post, please take a look at the following article by Arnie Rowland which provides some information that will help you form your questions in a manner that allows us to help you faster and with more accurate answers for your problems.

     

    How can I Prepare My Question to Increase the Possibility of Getting a Good Solution?

     

    There is not enough information to really answer your question accurately based on what you have provided.  If the two tables are the same, then you can try using the except operation as follows:

     

    Code Snippet

    select * from tablea

    except

    select * from tableb

     

     

    If they share a common primary key, then you could also do a left join between the table and filter on the absence of data in the second table to find the rows missing:

     

    Code Snippet

    select tablea.*

    from tablea

    left join tableb on tablea.rowid = tableb.rowid

    where tableb.rowid is null

     

     

    or you could have a completely different type of problem that is not distinct in your post, and we won't be able to help with unless you provide the information mlisted in the article like I provided above.

     

    Sunday, December 7, 2008 9:47 PM

All replies

  • Matka,

     

    Welcome to the MSDN Forums.  Since this is your first post, please take a look at the following article by Arnie Rowland which provides some information that will help you form your questions in a manner that allows us to help you faster and with more accurate answers for your problems.

     

    How can I Prepare My Question to Increase the Possibility of Getting a Good Solution?

     

    There is not enough information to really answer your question accurately based on what you have provided.  If the two tables are the same, then you can try using the except operation as follows:

     

    Code Snippet

    select * from tablea

    except

    select * from tableb

     

     

    If they share a common primary key, then you could also do a left join between the table and filter on the absence of data in the second table to find the rows missing:

     

    Code Snippet

    select tablea.*

    from tablea

    left join tableb on tablea.rowid = tableb.rowid

    where tableb.rowid is null

     

     

    or you could have a completely different type of problem that is not distinct in your post, and we won't be able to help with unless you provide the information mlisted in the article like I provided above.

     

    Sunday, December 7, 2008 9:47 PM
  • This was so quick and worked too.

     

    Thanks a lot.

     

    Monday, December 8, 2008 2:57 AM