Click here to Skip to main content
15,905,323 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear all,

I want to get data in this way. I have 2 tables.

Table1:
C#
INST_CODE          ADDRESS          PHONE        EMAIL

DPS101               DELHI        011965321    DPSDEL@IN
GLA02                NOIDA        12036450      swa@in



TABLE2
C#
ID       INST_CODE           CITY           OPENING        POSITION          INST_ID

1         DPS101             DELHI            2             SALES             1
2         DPS101             DELHI            5            TECHNICAL          1
3         GLA02              NOIDA            1             SALES             2




RESULT LIKE
C#
INST_CODE            ADDRESS            PHONE           EMAIL        TYPE

DPS101                DELHI            012063548       DPSDEL@IN     SALES
DPS101                DELHI            012063548       DPSDEL@IN    TECHNICAL
GLA02                 NOIDA            012365466       swa@in       SALES
Posted
Updated 7-Oct-14 1:22am
v2
Comments
Kornfeld Eliyahu Peter 7-Oct-14 6:55am    
http://mattgemmell.com/what-have-you-tried/

Start with basics: SQL JOINS[^]. There is few types of joins. The difference is presented here: Visual Representation of SQL Joins[^]

INNER JOIN sample:
SQL
SELECT t1.Field1, t1.Field2, t2.Field1, t2.Field2
FROM Table1 AS t1 INNER JOIN Table2 AS t2 ON t1.Key = t2.ForeignKey
 
Share this answer
 
Comments
[no name] 7-Oct-14 7:04am    
Thank you for the second link, it is great! My 5.
Regards, Bruno
Maciej Los 7-Oct-14 9:13am    
Thank you, Bruno ;)
Cheers,
Maciej
Try joining from table 2 to table 1.

SQL
Select T2.INST_CODE, T1.ADDRESS, T1.PHONE, T1.EMAIL, T2.POSITION
 
 From TABLE2 as T2
 InnerJoin TABLE1 as T1
 ON T2.INST_CODE = T1.INST_CODE



Something like that anyway!
 
Share this answer
 
It is very Simple dear. Just use Inner Join
SQL
SELECT
  T1.INST_CODE,
  T1.ADDRESS,
  T1.PHONE,
  T1.EMAIL,
  T2.POSITION AS [TYPE]
FROM
  table1 T1 WITH(NOLOCK)
  JOIN table2 T2 WITH(NOLOCK) ON T1.INST_CODE=T2.INST_CODE<
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900