Solved

SQl query help

Posted on 2013-05-14
6
122 Views
Last Modified: 2013-05-15
Hello,
There are 2 tables PhTheraChange  and TherachangeFacilityList .Both are joined by the facid.
how can I include the facname from therachangefacilitylist for those distinct phnpi's.

  select distinct c.PhNPI from PhTheraChange c 
      inner join TherachangeFacilityList t on t.facid = c.FacID

Open in new window

0
Comment
Question by:Star79
6 Comments
 
LVL 16

Expert Comment

by:Surendra Nath
ID: 39166408
try the below one

select distinct c.PhNPI,t.facname  from PhTheraChange c 
      inner join TherachangeFacilityList t on t.facid = c.FacID

Open in new window

0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39166410
Give this a whirl...

SELECT distinct c.PhNPI, t.facname
FROM PhTheraChange c
      JOIN TherachangeFacilityList t on t.facid = c.FacID
0
 
LVL 7

Expert Comment

by:Ross Turner
ID: 39166417
I'm not sure if I.m getting you but :

Have you got some sample data


select distinct
c.PhNPI,
T.facname
from PhTheraChange c
inner join TherachangeFacilityList t on t.facid = c.FacID
0
 

Author Comment

by:Star79
ID: 39166515
if i use
 this
SELECT distinct c.PhNPI, t.facname
FROM PhTheraChange c 
      JOIN TherachangeFacilityList t on t.facid = c.FacID 

Open in new window

it actually adds the distinct phnpi + the facnames.It doesnt give me the facnames of those distinct phnpi's
0
 
LVL 40

Accepted Solution

by:
Sharath earned 500 total points
ID: 39166533
try this.
SELECT c.PhNPI, max(t.facname) facname
FROM PhTheraChange c 
      JOIN TherachangeFacilityList t on t.facid = c.FacID
	  group by c.PhNPI

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now