Click here to Skip to main content
15,905,587 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hai all

i had two tables as follows:-
first table: Profile:
Id Name    Age Designation_code
1   ABC 22  3
2   DEF 24  2
3   GHI 25  1
4   JKL 23  3
5   MNO 22  3
6   PQR 25  2

Second Table: Designation:

D_id   Designation_name Designation_code
1   Consultant           E1
2   Project Lead         E2
3   Programmer           E3

i want to combine the tables and want the query result in this way
D_id   Designation name    Employees
1   Consultant              GHI
2   Project Lead            DEF
                            PQR
3   Programmer              ABC
                            JKL
                            MNO

can any one help me to do this...

know the query to join two table
SQL
SELECT p.Id,d.Designation_name,p.Name as Employee
FROM profile p
LEFT OUTER JOIN Designation d
ON p.Designation_code=d.Designation_code

but the result is coming out as follows
D_id    Designation name    Employees
1   Consultant              GHI
2   Project Lead            DEF
3   Project Lead            PQR
4   Programmer              ABC
5   Programmer              JKL
6   Programmer              MNO

so please any one help me
Posted
Updated 27-Apr-12 20:53pm
v2

1 solution

How to write sql query for generating result
know the query to join two table
but the result is coming out as follows

I would not suggest you that SQL queried data should be manipulated/filtered via query in this case.
What you got from query result is perfectly fine. You should not try to make any further changes in query to get the desired result.
Here, the final result is something that should be done in the front end on UI side.

Take the entire result and then hide the duplicate in the UI. I already shared exampled with you earlier: i want to populate grid view with data from more than two sql server tables[^]


No point in reposting again. If you think or don't find it suitable, talk to your senior/teacher to get direction.
 
Share this answer
 
Comments
VJ Reddy 28-Apr-12 4:40am    
Good suggestion. 5!

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