I need your help to solve one query for retrieve data like 'ResultTable' from 3 Different Sql Table and Below i give one exmple:
Both Table :Student and Employer Table data insert in to one Table TopicPostTable
Result Table: in TopicPostTable where UserType is 'Emp' then it join with EmployerTable and UserType is 'Stn' then it join with StudentTable
| StudentTable | ||
| SID | Name | |
| 1 | Rohan | [email protected] |
| 2 | Ajay | [email protected] |
| EmployerTable | ||
| EID | Name | |
| 1 | Anna | [email protected] |
| 2 | Bittu | [email protected] |
Both Table :Student and Employer Table data insert in to one Table TopicPostTable
| TopicPostTable | ||
| PID | UserType | |
| 1 | [email protected] | Emp |
| 2 | [email protected] | Emp |
| 3 | [email protected] | Stn |
Result Table: in TopicPostTable where UserType is 'Emp' then it join with EmployerTable and UserType is 'Stn' then it join with StudentTable
| EmplyerTable | ||
| PID | Name | |
| 1 | [email protected] | Anna |
| 2 | [email protected] | Bittu |
| 3 | [email protected] | Rohan |
Thanks...
Sanjeeb LenkaPosted Aug 31, 2013, 2:41 AM
try this:
SELECT e.NAME,e.eMail,P.PID
FROM
(SELECT NAME,Email FROM StudentTable
UNION
SELECT NAME,Email FROM EmployerTable)
AS e
INNER JOIN
TopicPostTable p
ON
p.email=e.email
Suresh BabuPosted Aug 31, 2013, 2:12 AM