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)
 Join table problem

Author  Topic 

Chengli
Starting Member

10 Posts

Posted - 2008-07-14 : 07:05:16
i got the problem when i would like to display data. for example :
table : monitor : M_Id, M_Model
MonitorCopy: M_id, Mcopy_ID,M_status
Cpu: C_Id, C_Model
CpuCopy : C_ID, Ccopy_Id,C_Model
GetPC : GETPC_ID, C_ID, Ccopy_Id, M_id, Mcopy_ID

and then i would like to display data like that
-----------------------------------
GETPC_ID C_Model M_Model
----------------------------------

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-14 : 07:07:27
http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-14 : 07:13:31
Didnt understand the difficulty here. A straightforward join will give you the desired result.


SELECT g.GETPC_ID,c.C_Model,m.M_Model
FROM GetPC g
INNER JOIN Cpu c ON c.C_Id,=g.C_Id
INNER JOIN monitor m ON m.M_id=g.M_id
Go to Top of Page

Chengli
Starting Member

10 Posts

Posted - 2008-07-14 : 07:18:44
sorry to all of u ... forget to say that

The data display i only want to show the data in the GetPC.
For example:
table- getPc
---------------------------------
GETPC_ID C_ID Ccopy_Id M_id Mcopy_ID
p1 c1 cp1 m1 mc1

table - Cpu
---------------------------------
C_ID cModel
c1 Hp
c2 Acer
---------------------------------

table - CpuCopy
---------------------------------
C_ID Ccopy_Id status
c1 CP1 Yes
c2 1p2 no
---------------------------------

Data i would like to dis play is like that :

GETPC_ID C_Model
p1 Hp

Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-07-14 : 07:25:53
SELECT G.GETPC_ID,C.C_MODEL
FROM GETPC G
INNER JOIN CPU C ON C.C_ID = G.C_ID
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-07-14 : 08:02:46
quote:
Originally posted by Chengli

sorry to all of u ... forget to say that

The data display i only want to show the data in the GetPC.
For example:
table- getPc
---------------------------------
GETPC_ID C_ID Ccopy_Id M_id Mcopy_ID
p1 c1 cp1 m1 mc1

table - Cpu
---------------------------------
C_ID cModel
c1 Hp
c2 Acer
---------------------------------

table - CpuCopy
---------------------------------
C_ID Ccopy_Id status
c1 CP1 Yes
c2 1p2 no
---------------------------------

Data i would like to dis play is like that :

GETPC_ID C_Model
p1 Hp




cant you try this modification from solution provided earlier?
Go to Top of Page
   

- Advertisement -