|
|
|
Custom Search
| |
|
| |
|
Eliminating Duplicate Rows
When the result set from a SELECT statement contains duplicate rows, you may want to remove them and keep every row data to be unique for a column or combination of columns. You can use the DISTINCT or DISTINCTROW identifier to eliminate duplicate records. DISTINCT and DISTINCTROW are synonyms and specify removal of duplicate rows from the result set. Read Prerequisites for this tutorial and practices if you haven't done so. Consider the following facts when using DISTINCT or DISTINCTROW identifier in a SELECT statement:
Practice #1: Retrieve distinct rows for one column. In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. -- Display distinct Quantity values The query above retrieves distinct quantity data from order_details table. There are total 55 rows retrieved out of 2,155 rows in order_details table.
Query result set: Practice #2: Retrieve distinct rows for the combination of two columns. In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. -- Retrieve distinct rows based on There are total 238 rows retrieved out of 2,155 rows in order_details table.
Query result set: Practice #3: Retrieve distinct rows for the combination of three columns. In Firefox (not IE), copy and paste the following SQL to your SQLyog query window. Note that the SQL needs to end with semi-colon if you have multiple queries in the query window. Most of the queries in the tutorials need Northwind MySQL database, you can download the database script on this page. -- Retrieve distinct rows based on three There are total 1,711 rows retrieved out of 2,155 rows in order_details table.
Query result set:
|
|
Copyright © 2012 GeeksEngine.com. All Rights Reserved. This website is hosted by LunarPages. No portion may be reproduced without my written permission. Software and hardware names mentioned on this site are registered trademarks of their respective companies. Should any right be infringed, it is totally unintentional. Drop me an email and I will promptly and gladly rectify it. |
| Home | Kung Fu Timer | Feedback | Terms of Use | Privacy Policy |