Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Administration
 Question about query

Author  Topic 

anat
Starting Member

3 Posts

Posted - 2010-10-17 : 04:55:39
Hello,
My question is about query I realy can't generate (If this is not the place, sorry...)
I have two rables: Table1 with fiekds: F1, F2, F3 and table2 with fields F1, F2, F3.
I would like to have all the records that are equal in their F1 and F2 fields, and are differnt in their F3 field, comarison the two tables.
In a schematic way:
table1.F1=table2.F1
and table1.F2=table2.F2
and table1.F3 <> table2.F3
With these three condition in "Where", it does not work.
I know it seems easy, but I can't do it...
I'll appreciate any help with that
Thanks!

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-17 : 07:14:18
But it works:
declare @table1 table ( F1 int, F2 int, F3 int)
declare @table2 table ( F1 int, F2 int, F3 int)

insert @table1
select 1,1,1 union all
select 2,2,2 union all
select 3,3,3

insert @table2
select 1,1,1 union all
select 2,2,2 union all
select 3,3,4

select *
from @table1 t1
join @table2 t2
on t2.F1 = t1.F1
and t2.F2 = t1.F2
and t2.F3 <> t1.F3




No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

anat
Starting Member

3 Posts

Posted - 2010-10-17 : 07:55:16
Thanks for answering me :-))
But unfortunatly it doesn't work.
One record in the output contains the same F3 fields (which supposed to be the different one).

Any other suggestions?

Thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-17 : 09:11:50
nope. in that case there might be something different between them, may be some unprintable characters like space, carriage return etc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

anat
Starting Member

3 Posts

Posted - 2010-10-18 : 07:23:13
yes, you are right!
There was 'enter': chr(10) and chr(13) which I replaced.

Thanks again
Anat
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-19 : 13:16:48
Cool

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -