I was working on a little query
which works just fine, but there were other issues, so as we were looking over the entire PR, he suggested changing the JOINS to look more like
Now, my question is related to performance. In the past I would avoid things like this because of performance issues. However, I am at a new job where we are pulling data out of SQL Server to give to statisticians for analysis. Our database is underutilized and none of the tables are really large (maybe 150k records at the most), so performance isn't likely to be an issue, but are there potential performance issues with structuring the joins like that?
wb
Code:
SELECT C.STUDY_PARTICIPANT_ID,
C.STUDY_PROTOCOL_ID,
C.STUDY_SITE_ID,
PHS.PROC_LABS_PSA_DATE,
PHS.PROC_LABS_PSA_VALUE,
PHS.PROC_LABS_PSATESTNAME_CODE,
PHS.PROC_LABS_PSATESTNAMEOTHER_TEXT,
getdate() AS AccessDate
FROM dbo.TBLCONSENT C JOIN TBLPSAHISTORYSUB PHS
ON C.Study_Participant_ID = PHS.Study_Participant_ID
JOIN tblFinalG FG ON C.Study_Participant_ID = FG.Study_Participant_ID
WHERE C.DeleteFlag=0
AND C.EntryFlag=1
AND PHS.DeleteFlag=0
Code:
SELECT C.STUDY_PARTICIPANT_ID,
C.STUDY_PROTOCOL_ID,
C.STUDY_SITE_ID,
PHS.PROC_LABS_PSA_DATE,
PHS.PROC_LABS_PSA_VALUE,
PHS.PROC_LABS_PSATESTNAME_CODE,
PHS.PROC_LABS_PSATESTNAMEOTHER_TEXT,
getdate() AS AccessDate
FROM (SELECT * FROM tblFinalG WHERE deleteflag=0) AS FG
JOIN (SELECT * FROM dbo.TBLCONSENT WHERE deleteflag=0 and entryflag=1) AS C ON FG.Study_Participant_ID = C.Study_Participant_ID
JOIN (SELECT * FROM TBLPSAHISTORYSUB WHERE deleteflag=0) AS PHS ON FG.Study_Participant_ID = PHS.Study_Participant_ID
JOIN (SELECT * FROM tblPSAHistory WHERE deleteflag=0 and entryflag=1) AS PH ON FG.Study_Participant_ID = PH.Study_Participant_ID
wb