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 Programming
 Join Help

Author  Topic 

xrum
Yak Posting Veteran

87 Posts

Posted - 2011-01-05 : 15:12:28
Hi,

my first table has about 18K records

so when i

select * from table2 i get about 18k

i'm trying to do a join on it as follows, but i'm getting like 26K back.. what am i doing wrong? i though it's supposed to return all of the "right" aka table2 records plus show me whatever value matches from the first in a separate column...

Select t1.fID , t2.*
FROM table1 t1 right join table2 t2 on t1.fName = t2.f

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-01-05 : 15:39:03
Impossible to tell. Getting more rows back usually means that thre's not a one-to-one relationship between your tables -- there's something else you need to join on maybe you need to do aggregate table2 before joining

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

xrum
Yak Posting Veteran

87 Posts

Posted - 2011-01-05 : 15:44:20
here is an exmaple of my tables:

table 1: fID, fName

table 2: id, f, address, etc

i need to get all records from table 2, with an fID column, whenever f=fName

is it possible? table 1 has unique fNames, while f may match more then once to fName....
Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2011-01-06 : 03:59:54
Try this:
select t1.fid, t1.fname
from table1 t1 inner join table2 t2
on t1.fname = t2.fid
Go to Top of Page
   

- Advertisement -