Hi I have a SQL query that I don't quite understand why is producing what is producing.
Here is the example of the query statement:
Code:
SELECT tableEXAMPLE.ID, tableEXAMPLE.B, tableEXAMPLE.C, tableEXAMPLE.D, tableEXAMPLE.E
FROM tableEXAMPLE
GROUP BY tableEXAMPLE.ID, tableEXAMPLE.B, tableEXAMPLE.C, tableEXAMPLE.D, tableEXAMPLE.E
HAVING ((
(tableEXAMPLE.ID) IN (SELECT TOP 10 PERCENT ID FROM tableEXAMPLE as q
WHERE q.C = tableEXAMPLE.C and t.D = tableEXAMPLE.D ORDER BY id)));
tableEXAMPLE has 1304 records, ID is a unique identifier for all 1304 records. So GROUP BY is
not condensing any of the 1304 records. Field C and D can have duplicated records. After running
the SQL statement I got a total of 195 records as it's result.
My question is why and how the SQL statement on top is different than this one below,
I get a result of 131 records which is 10% of 1304.
How is the top one giving a very different result (195 records) than the bottom, I don't understand even
after I did my own investigation. Could someone help explain this to me. Thanks, appreciate it !!! :-)
Code:
SELECT TOP 10 PERCENT tableEXAMPLE.ID, tableEXAMPLE.B, tableEXAMPLE.C, tableEXAMPLE.D, tableEXAMPLE.E
FROM tableEXAMPLE
GROUP BY tableEXAMPLE.ID, tableEXAMPLE.B, tableEXAMPLE.C, tableEXAMPLE.D, tableEXAMPLE.E