I am trying to figure out how to get distinct records from a query similar to the following (snippet from a larger query):
If I run the SELECT DISTINCT statement alone, it indeed does bring back distinct records. But when I nest it within the SELECT * statement, I'm still getting duplicates. I understand why...there are multiple col_02 records that are IN the distinct selection of col_02 records. But how can I get around it?
Code:
INSERT INTO tbl_01
(SELECT * FROM tbl_02 t2 WHERE col_02 IN
(SELECT DISTINCT col_02 FROM tbl_02 WHERE col_01 = t2.col_01
)
)
If I run the SELECT DISTINCT statement alone, it indeed does bring back distinct records. But when I nest it within the SELECT * statement, I'm still getting duplicates. I understand why...there are multiple col_02 records that are IN the distinct selection of col_02 records. But how can I get around it?