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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Problem in Joins

Author  Topic 

ChandanJ
Starting Member

6 Posts

Posted - 2007-10-19 : 13:56:25
Hi,
I'm stuck in some basic problem of joins.
I have two tables, eg- Table1 & Table2. There are 3 columns each in both the tables.
Table1 & Table 2 has two rows
-----------
Table1
------------
Col1 Col2 Col3
200 ABC 1
200 ABC 2
----------
Table2
---------
Col1 Col2 Col3
200 ABC 8
200 ABC 9

I want the result as
--------
Result
--------
Col1 Col2 Col3 T2Col3
200 ABC 1 8
200 ABC 2 9
-----------------------------------

The query i'm using is
------------------------------------------
SELECT T1.Col1, T1.Col2, T1.Col3, T2.Col3
FROM Table1 T1 INNER JOIN Table2 T2 ON
T1.Col1 = T2.Col1 AND T1.Col2 = T2.Col2
--------------------------------------------
But this query is returning me four rows. Please help me out to get the resultant table.
Any help will be appreciated.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-10-20 : 01:51:15
what is your logic of associating Table1's record "200 ABC 1" to Table2's "200 ABC 8" ?



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-10-21 : 10:21:08
Guessing your result looks like:

200 ABC 1
200 ABC 2
200 ABC 8
200 ABC 9


Is that correct?

Are these definitely unique values? If there are values:
200 ABC <NULL> in those columns for both tables, you will get multiple records as shown above

Try adding:
SELECT T1.Col1, T1.Col2, T1.Col3, T2.Col3
FROM Table1 T1 INNER JOIN Table2 T2 ON
T1.Col1 = T2.Col1 AND T1.Col2 = T2.Col2
where T1.Col3 is not null and T2.Col3 is not null



Go to Top of Page
   

- Advertisement -