tsql - SQL help: find rows in one table which don't exist in second table based on values in two columns -


I have two tables I'm trying to find rows in a table that, based on values ​​in two columns, The table does not exist. (I have simplified the table to include only two columns). There is no primary / foreign key between the two tables. Looks simple enough, but now I have a brain block!

  DDL: Make Table [DBO]. [Table_1] ([first name] [ench] (10) zero, [last name] [nchar] [10] tap) [table]] [table 2] ([first name] [nchar] (10) tap, Last name] [nchar] (10) null)  

- - Create sample data

  INSERT [dbo]. [Table_1] (Select [first name], [last name]) N'John, N'Doe 'UNION ALL SELECT N'John', N'Smith 'INSERT IN [DBO] [Table-2] ([First name ], [Last name]) SELECT N'John, N'Doe '-  

- My unsuccessful attempt is to expect John Smith's return

  SELECT t * Select from where Table_1 is not available (Select from T2. * Table 2 to T2 WHERE t.firstname & lt;> gt; t2.firstname and t .lastname & lt; & gt; t2.lastname) * T2 on T. Fastname as T-Zen Table 2 as Tablet & lt; & Gt; T2.firstname and t.lastname & lt; & Gt; Join T1 Left OUTER as Table_1 on Table 2 as T2 on T1. First name = t 2.firstname and t1.lastname = t2.lastname WHERE t2.firstname is NULL and t2.lastname is faucet  

In my case, I only get John Smith .

You basically do an external participant between the tables on common areas - both of which are present in the line t1 and t2 < Value for both / code>

Those rows are present only in t1 , there will be no value for the second table t2 .


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -