| Author |
Topic  |
|
|
Johnph
Yak Posting Veteran
75 Posts |
Posted - 07/25/2012 : 09:14:31
|
I have table 1 with columns "FIRST_NAME" and "LAST_NAME" table 2 with columns "FIRST_NAME" and "MIDDLE_INT"
I need a query that can grab all "FIRST_NAME" in table 1 that ARE NOT in table 2 and include an ID column listing them as 1,2,3,4,5,6 etc.
Any help on this issue would be great. |
|
|
nigelrivett
Flowing Fount of Yak Knowledge
United Kingdom
3328 Posts |
Posted - 07/25/2012 : 09:19:35
|
select id, first_name from tbl1 where first_name not in (select first_name) from tbl2)
or maybe select distinct first_name, id = row_number() over (order by first_name) from tbl1 where first_name not in (select first_name) from tbl2)
========================================== Cursors are useful if you don't know sql. SSIS can be used in a similar way. Beer is not cold and it isn't fizzy. |
 |
|
|
Johnph
Yak Posting Veteran
75 Posts |
Posted - 07/25/2012 : 09:27:33
|
| Hey, the second query worked perfectly. Thank you! |
 |
|
|
Johnph
Yak Posting Veteran
75 Posts |
Posted - 07/25/2012 : 09:35:06
|
| Actually, is there a way to make the ID column varchar instead of BIGINT? |
 |
|
|
nigelrivett
Flowing Fount of Yak Knowledge
United Kingdom
3328 Posts |
Posted - 07/25/2012 : 10:21:44
|
select first_name, id = converrt(varchar(20),id) from ( select distinct first_name, id = row_number() over (order by first_name) from tbl1 where first_name not in (select first_name) from tbl2) ) a
========================================== Cursors are useful if you don't know sql. SSIS can be used in a similar way. Beer is not cold and it isn't fizzy. |
 |
|
| |
Topic  |
|