Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How do you pull from two tables?

Author  Topic 

dibbs
Starting Member

2 Posts

Posted - 2011-07-28 : 21:56:07
I've got two tables, one called "MWPATIENTS" and one called "MWTRN". There is a common field called "Chart Number" that is in both tables.

The MWPATIENTS table has all the patient information such as full name, address, etc.

I need to run a query on the MWTRN table that selects certain records and then get the patients full name from the MWPATIENT table.

select "Chart Number", "Procedure Code" from mwtrn WHERE "Procedure Code" = 'G0121' or "Procedure Code" = 'G0105'

It shows the chart number OK, but now I need to get the patients name from the MWPATIENT table.

Any suggestions please?

http://dibbsolutions.com

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-07-28 : 22:53:35
you use INNER JOIN to join the two table together


SELECT t.[Chart Number], t.[Procedure Code], p.[Patient Name], p.[Address]
FROM MWTRN AS t
INNER JOIN MWPATIENTS AS p ON t.[Chart Number] = p.[Chart Number]
WHERE t.[Procedure Code] = 'G0121'
OR t.[Procedure Code] = 'G0105'



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

dibbs
Starting Member

2 Posts

Posted - 2011-07-28 : 23:05:30
Hey thanks, that worked great!

http://dibbsolutions.com
Go to Top of Page
   

- Advertisement -