Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQl query help

Posted on 2013-05-14
6
Medium Priority
?
129 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
5 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 66

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 41

Accepted Solution

by:
Sharath earned 2000 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

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

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

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
     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 …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

877 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