My query works fine; however, I need to join another dataset to my query, and I expect that the count(f.*) will break.
Here’s the query I start with:
SELECT
MIN(received_date) AS FirstVisit
, patient_id AS PatientID
INTO #LookupTable
FROM F_ACCESSION_DAILY
SELECT
f.doctor AS Doctor
, COUNT(f.*) AS CountNewPatients
, MONTH(firstvisit) AS Month
, YEAR(firstvisit) AS Year
FROM F_ACCESSION_DAILY f
INNER JOIN #LookupTable l ON f.received_date = l.FirstVisit
AND f.patient_id = l.PatientID
GROUP BY f.doctor
, MONTH(firstvisit)
, YEAR(firstvisit)
DROP TABLE #LookupTable
I would like to Join the above query on another table.
The question is *will my count(f.*) stay the same or will it change because I’ve added a new dataset?*
**How do I make sure that the count(f.*) will remain the same?
Thank you so much for your guidance.
COUNT(*)counts rows. If you join another table and the number of rows increases, the result ofCOUNT(*)will increase.Use
COUNT (DISTINCT f.Id).