November 19, 2009 at 12:37 pm
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
November 19, 2009 at 12:52 pm
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
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply