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 to join 2 table

Author  Topic 

prashantsarada99
Starting Member

1 Post

Posted - 2008-06-12 : 06:26:02

i have 2 table patient & PatientServiced and i want to join both the table the common field is id(patient) & patient_id(patientservices) so what will be the sql query for it?

SELECT [id], [firstName], [lastName], [middleName], [streetAddress], [city], [state], [zip], [phone], [gender], [dob], [age], [serviceDate], [clinic_id], [entryDate], [emailAddress], [enteredBy], [importId] FROM [FCID_2].[dbo].[Patient]

SELECT [id], [patient_id], [value], [topNumber], [bottomNumber], [patientService_id], [patientPaid], [insuranceAmtRequested], [insuranceAmtPaid], [insuranceBalance], [totalPaid], [batchID], [status], [dateSent], [datePaid], [dateDeclined], [declinedReason], [correctionNote], [dateEntered], [enteredBy], [insuranceProvider_id], [insuredMemberID], [insuredGroupID], [insuredFirstName], [insuredLastName], [insuredRelationship], [adjustedReason], [remitDetail], [correctedClaim] FROM [FCID_2].[dbo].[PatientServiced]

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-12 : 06:28:48
SELECT *
FROM [FCID_2].[dbo].[Patient] t1
INNER JOIN [FCID_2].[dbo].[PatientServiced] t2
ON t2.[patient_id]=t1.[id]

Remember to replace * with columns you want (if you dont want all of them)

Also read about joins in books online to understand how they work
Go to Top of Page
   

- Advertisement -