Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all


SQL
select p.title from project_info pi inner join project_member pm where pi.projectid = pm.projectid and pm.name = 'bhagirathi'

union 

select p.title form project_info pi inner join project_test_member ptm where pi.projectid = ptm.projectid and ptm.name = 'bhagirathi';



How to solve the above problem without using union ,in one select query?

Thanks In advance.
Posted
Updated 16-Apr-12 1:42am
v3
Comments
Herman<T>.Instance 16-Apr-12 9:18am    
what is your exact goal? please show example
bhagirathimfs 16-Apr-12 9:47am    
bhagirathi is an employee.
some projects are assigned to him and stored in project_member table and some testing projects are assigned to him and stored in project_test_member table.

Now i want to see the projects assigned(both normal project and the test project) to bhagirathi.

I have written the above code and it is showing the result but i want use join instant of union.

you must use union
its the good way

SQL
select t  from (

select p.title as t from project_info pi 
Right join project_member pm on pm.projectid = pi.projectid 
right join project_test_member ptm on pi.projectid = ptm.projectid 
) where t = 'bhagirathi';

not sure may it works
 
Share this answer
 
v3
Comments
bhagirathimfs 16-Apr-12 7:45am    
It is possible to solve the above problem using any join.

Thanks
Photon_ 16-Apr-12 8:05am    
in union rows are joined and in join columns are joined do you still think the same its easy to do with union or intersection
Photon_ 16-Apr-12 8:11am    
if it solve your problem please upvote
bhagirathimfs 16-Apr-12 9:50am    
sry photon here bhagirathi is not the title of the project it is an employee name for which i want to see the project titles assigned to him.
Photon_ 16-Apr-12 10:38am    
Sorry i'll update it 2 Amar this time i'm from mobile and I think you can make some changes to get exact what you want
Try Like This
SQL
select p.title from project_info pi inner join project_member pm 
on
 pi.projectid = pm.projectid 
inner join
project_test_member ptm 
on
 pi.projectid = ptm.projectid 
where  ptm.name = 'bhagirathi' and  pm.name = 'bhagirathi'
 
Share this answer
 
Comments
bhagirathimfs 16-Apr-12 7:53am    
It is showing null.
Herman<T>.Instance 16-Apr-12 9:18am    
what happens if you set the last AND to OR ?
bhagirathimfs 16-Apr-12 9:47am    
it is showing the projects of project_test_member not the project_member project if we use or .
Herman<T>.Instance 16-Apr-12 10:40am    
and when where ptm.name = 'bhagirathi' or pm.name = 'bhagirathi' is changed to where ( ptm.name = 'bhagirathi' or pm.name = 'bhagirathi' )
bhagirathimfs 17-Apr-12 2:54am    
Yes it is working

Thanks for solving my problem
Thanks a ton

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