|
很有收获。
Here are some thoughts:
1) use of distinct
for this particular case, distinct may not be necessary. However, if we generalize the case, then the issue becomes how to get a row or rows which is max or min in certain fields. In other words, dups are allowed in the table. In that case, the use of distinct will be determined by business requirements.
2) exists or not
The test table is very small, and has no indices. In fact, even if indices were created, they probably would not be used any way, because the cost of a table scan will be much less in that case (to the optimizer). For bigger tables (say, over 1 million of records), things will be different. Not exists is not ideal in that case (definitely inferior to just "exists" . Max/Min will probably not fare much better either. We will only know it through tests and query plan analysis. |
|