Solved

SQl query help

Posted on 2013-05-14
6
127 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
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…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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