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 2005 Forums
 Transact-SQL (2005)
 Problem with JOIN query

Author  Topic 

avtuvy
Starting Member

9 Posts

Posted - 2010-01-09 : 15:28:03
I have a group of three tables



TBL_ServerInformation

SerialNumber ServerName
------------------------
1 Phantom
2 Mirage
3 Skyhawk
6 Bison
9 Fuga
15 shark
16 Tuna

TBL_ServerIP
UniqueID IPAddress SerialNumber
----------- --------------- ------------
1 1.1.1.3 1
2 1.1.1.4 1
3 1.1.1.5 1
4 1.2.3.4 2
5 1.2.3.5 2
6 12.34.67.89 3
7 216.45.67.89 15
8 23.56.89.0 6
9 255.255.25.1 9
10 32.67.90.3 16
11 89.80.45.7 6

UniqueID PortNumber
----------- -----------
1 7400
1 7401
2 7434
2 65000
2 7654
3 54
3 21
3 4566


I am running the query


SELECT dbo.TBL_ServerInformation.ServerName, dbo.TBL_ServerIP.IPAddress, dbo.TBL_Port.PortNumber
FROM dbo.TBL_ServerInformation INNER JOIN
dbo.TBL_ServerIP ON dbo.TBL_ServerInformation.SerialNumber = dbo.TBL_ServerIP.SerialNumber
INNER JOIN dbo.TBL_Port ON dbo.TBL_ServerIP.UniqueID = dbo.TBL_Port.UniqueID


And in the result I get the same name for all entries instead of the correct names pleas help

ServerName IPAddress PortNumber
------------ --------------- -----------
Phantom 1.1.1.3 7400
Phantom 1.1.1.3 7401
Phantom 1.1.1.4 7434
Phantom 1.1.1.4 65000
Phantom 1.1.1.4 7654
Phantom 1.1.1.5 54
Phantom 1.1.1.5 21
Phantom 1.1.1.5 4566

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-09 : 15:34:59
The output is exactly what your query should bring!


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

avtuvy
Starting Member

9 Posts

Posted - 2010-01-09 : 15:54:22
Thanks you are right, I am looking at that thing for an hour and did not realize it.
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-09 : 16:00:12
Sometimes a second pair of eyes is very helpful


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

- Advertisement -