I'm receiving more ID's then possible after performing a left outer join statement on two tables.
Context: I've narrowed down two tables from larger data sets. Below are the queries found I've used to obtain IDs possible after selecting from the larger data set. I am trying to JOIN two data sets together based upon the personID. I am preforming a LEFT JOIN because I want to retain all data in the smallerset table while pairing it with data from narrowed data table.
Upon running this query on a subset of a larger data set I receive the following IDs:
select s.personID from st.smallerset as s;
41486
41490
41493
41496
...
Now, upon running the second query, I receive the following:
select r.* from st.secondlargedataset as r,
st.condition as h where r.personID=h.personID group by r.personID;
I receive the following queries:
41544
41577
41595
41605
...
So far, so good. Everything is as expected. However, when I run this next subquery as I try to join these two subsets I get unexpected results.
select s.personID
from st.smallerset as s left join
(select r.* from st.secondlargedataset as r,
st.condition as h where r.personID=h.personID group by r.personID) as v on
s.personID=v.personID;
41485
41486
41489
41490
41493
41496
41510
41512
41513
41516
Included in this result is data that is not include in either prior query. Specifically IDs 41485
, 41489
, 41496
et cetera. I'm clueless as to why these IDs are appearing since when I break the queries into separate queries I get the IDs I need.