Issue related to getting distinct records using join in SQL Server -


i have following columns in tblproject datatable:

id, title, estimator, constructioncoordinator, constructionmanager, enteredby, assignedto, projectcoordinator, saleslead 

all above column without first 2 entry of userid of tbluser datatable follows

userid, username 

i want records tblproject in columns(without first 2 i.e id , title) contains userid of tbluser

i tried following query,

 select * project prj  inner join userprofile on up.userid = prj.estimator or up.userid = prj.constructioncoordinator                     or up.userid = prj.constructionmanager or up.userid = prj.enteredby or up.userid = prj.assignedto                     or up.userid = prj.projectcoordinator or up.userid = prj.saleslead 

but getting duplicate records, in column id , title how distinct data ?

thanks

set based thinking, intersect analogous logical and , union analogous logical or, led me this:

select userid userprofile intersect ( select estimator project   union   select constructioncoordinator project   union   select constructionmanager project   union   select enteredby project   union   select assignedto project   union   select projectcoordinator project   union   select saleslead project ); 

to return columns, per sql, could:

select * project userid in  ( select estimator project   union   select constructioncoordinator project   union   select constructionmanager project   union   select enteredby project   union   select assignedto project   union   select projectcoordinator project   union   select saleslead project ); 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -