Compare two tables ("AND")

  • Hi,

    I have to tables: table1 (SomeID int) and table2(SomeID int). One column in each table. Please help to write query that will can to compare two tables, so we can know whether all rows (SomeID int) in table1 exists in table2. Query should return true or false.

    Examples:

    1. If table1 (SomeID int) has rows with values 1,2, and table2(SomeID int) has rows with values 1,2,3, then the query returns true.

    2. If table1 (SomeID int) has rows with values 1,4, and table2(SomeID int) has rows with values 1,2,3, then the query returns false.

    3. If table1 (SomeID int) is empty, and table2(SomeID int) has rows with values 1,2,3, then the query returns true

    Thanks in advance

  • looks an awful lot like homework, so lets see what you've done so far;

    we need to help you learn the concepts, and not do the work for you.

    did you actually create the example tables with CREATE TABLE statements yet? did you insert the data from the tables into the tables with INSERT INTO statements yet? this is a critical piece of learning SQL and debugging; building the data to test with.

    my hint for you is learning how to do joins. joins are used to find common or unique values between two tables.

    Review the differences between INNER JOIN,LEFT OUTER JOIN and FULL OUTER JOIN, and with minimal effort, I think you can get a working SQL going that will point you to the answers.

    if you show us your work, we can help you with any specific syntax or logic issues, but we need some effort on your part.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply