none
How to query two datasets and tables with a single Select Statement RRS feed

  • Question

  • I have two Databases with similar schema but different data. Both have a schools table which contains schools data. I have to append all schools data in one table which are not in the other table .  I am using two datasets for the same and want to implement the following query

    "SELECT * FROM School1 WHERE SCHCD NOT IN (SELECT SCHCD FROM school2)"

    Want help on ?

    1.  How to implement the query written above.

    2.  How can I add tables having similar names from two databases into a single Dataset and how to create DataRelations between them?

    3.  Can this task  be done with Command objects and/or DataAdapters and How?

    4. Can tables in two datasets can be used in a single query.

     


    Omprakash
    Wednesday, September 7, 2011 9:52 AM

All replies

  • You can try this:

    Select Q.* From 
    (
    Select * From School1DB.dbo.School
    
    UNION
    
    Select * From School2DB.dbo.School
    )Q
    
    


    Where School1DB & School2DB are two database of diff school.

    Union would give you only the unique records from all.


    Amit Govil | MyEmail
    Wednesday, September 7, 2011 10:14 AM