Click here to Skip to main content
15,888,287 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends, please help me.


I got stuck in one of my tasks, i.e I want to convert a union query into join query using and I should get the same output as if in union query. Please help me!

union query

select distinct p1.people_id,p1.fullname,p1.company_id,c1.company_name,p1.city,p1.state,p1.country,p1.user_id from people p1,company c1 where c1.company_id=p1.company_id and p1.verify_status='Yes' and p1.royalty='Yes' and p1.user_id='" + userID + "' and p1.delete_status='No' union select p1.people_id,p1.fullname,p1.company_id,c1.company_name,p1.city,p1.state,p1.country,p1.user_id from BackupPeople p1,company c1 where c1.company_id=p1.company_id and p1.user_id='" + userID + "'";



I want to convert it into join with same output.
Posted
Updated 1-Nov-10 20:30pm
v2

1 solution

SQL
SELECT DISTINCT p1.people_id,p1.fullname,p1.company_id,c1.company_name,p1.city,p1.state,p1.country,p1.user_id
FROM #people p1 INNER JOIN #company C1 ON c1.company_id=p1.company_id
                INNER JOIN #BackupPeople Bp1 ON c1.company_id=Bp1.company_id
WHERE
          p1.verify_status='Yes'
      AND p1.royalty='Yes'
      AND p1.user_id=1
      AND p1.delete_status='No'
 
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