How does distinct work in mysql
Read this: dev. Icarus What optimizations it performs is irrelevant, as long as the result set comes back the way you expect it to. Did you read the link? Looks to me that you need to do select select distinct Did you try it? Do you have a mysql box around that you can use to run a quick test and confirm the behavior?
I will install MySQL tonight and see it with my own eyes, but as I said, Aby is not the first one reporting this behavior. Be careful to read the above link. The order by only isn't guaranteed to work when you are trying to order by a column that isn't being selected.
If you order by something that is in the distinct column list it works just fine. Sign up or log in Sign up using Google.
Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. Function Call Optimization. Window Function Optimization. Row Constructor Expression Optimization. Avoiding Full Table Scans. Optimizing Subqueries with Materialization. Derived Condition Pushdown Optimization.
Optimizing Performance Schema Queries. Optimizing Data Change Statements. Optimizing Database Privileges. Other Optimization Tips. Primary Key Optimization. Foreign Key Optimization. Multiple-Column Indexes. For this, we can make the use of the distinct keyword. In MySQL, the distinct keyword or clause helps us to retrieve the unique or different values of the column in the table. In this article, we will learn about the usage of distinct keyword, its syntax, examples with NULL values, aggregate functions, more than one columns with a distinct function, and the similarities between distinct and group by clause.
Let us consider one example, Create one table names developers using the following create a query. We have inserted multiple values in my table using the same insert format. The query statement for this will be as follows —. As we can see, all the duplicate values of technology value are skipped and only distinct and different values are added in the result set. When defined on one column it retrieves the unique values of that column.
Select all the different values from the Country column in the Customers table. We just launched W3Schools videos. Get certified by completing a course today! If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:.
0コメント