Solved

SQl query help

Posted on 2013-05-14
6
124 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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