![]() ![]() ![]() Select all Open in new window Note: A query using GROUP BY is not nearly as boring as poor old “SELECT DISTINCT” and GROUP BY does offer quite a number of interesting options such as MAX(), MIN(), AVERAGE() etc.īUT I hear you say "I don’t want MAX() values or MIN() values and such like" ![]() from atable group by column1 -<< MUST be unique columns here Select column1, MAX(column2), MAX(column3). Select all Open in new window Second step: Decide what can be done with the other columns, Select column1 -<< MUST be unique columns here from atable group by column1 -<< MUST be unique columns here So, what to do? First step: Concentrate on the columns that MUST be unique, e.g. Select all Open in new window Small note: I personally would not describe this as “having duplicates”, I prefer to describe this as “unwanted repetition" blah! <<I'm unique! aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll. col27 aaaa bbbb cccc dddd eeee ffff gggg hhhh iiii jjjj kkkk llll. That might mean for example that a value containing an exclamation in column27 and a value that does not have an exclamation in column27 causes 2 rows to be returned even if every other column has the same values.Ĭol1 col2 col3 col4 col5 col6 col7 col8 col9 cl10 cl11 cl12. It will evaluate ALL of the columns that you have listed and remove rows that have exactly the same values in all columns so that each row returned is different to every other row that is returned. SELECT DISTINCT is a “row operator”, not a function, and not magic. You will be disappointed to learn that those parentheses around column1 do NOT work to “make column1 unique, then by magic decide how to simplify the other columns”.Īnd: With or without the parentheses, SELECT DISTINCT does not know that you really want it to concentrate on column1 or (column1 and column2) ignoring the other columns. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |