Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a table structure as
id|empname|type
1 raj hr
1 cat mr

and a another table as
type | description
hr he is hr
mr he is mr

I want to write a sql queries such that to should display data as

id | empname | type1 | desc1 | empname2 | type2 | desc2
1 raj hr he is hr cat mr he is mr

how can I do so.
i had tierd as
SQL
SELECT  dbo.empmst1.id, dbo.empmst1.name, dbo.emp1.description, dbo.emp1.types,(select
dbo.emp1.types as types2,dbo.emp1.description as desc2 from emp1)
FROM   dbo.empmst1 INNER JOIN
dbo.emp1 ON dbo.empmst1.types = dbo.emp1.types


but still no result, only an error
Posted
Updated 4-Mar-11 8:46am
v3
Comments
TweakBird 4-Mar-11 13:54pm    
What you have tried.? any effort?

Tip for you; start your query by joining 2 tables with the column "type".

Check here for an example;
Join_(SQL)[^]
 
Share this answer
 
v3
Try this:
SQL
SELECT dbo.empmst1.id, dbo.empmst1.name, dbo.emp1.description, dbo.emp1.types,
    dbo.emp1.types as types2, dbo.emp1.description as desc2
FROM dbo.empmst1
INNER JOIN dbo.emp1
ON dbo.empmst1.types = dbo.emp1.types


Notice you do not need the inner select as the table is already joined.
 
Share this answer
 
v2

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