Solved

SQl query help

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 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

19 Experts available now in Live!

Get 1:1 Help Now