DISTINCTROW
DISTINCTROW is an SQL clause that is used to ensure that all the rows returned from a query are unique. It takes into account all the columns in the result set to eliminate duplicate rows. This clause is particularly useful in database scenarios where you need to streamline your dataset by removing redundancy.
Example
Output
Explanation
The above SQL statement is used to select distinct (different) cities from the “Customers” table. The DISTINCTROW keyword ensures that each row is unique for the column specified.
Example
Output
Explanation
The DISTINCTROW
keyword can be used in a SQL SELECT statement to omit duplicate records from the results. In this example, the SELECT statement returns a list of unique order IDs and associated customer IDs from the Orders table. Records where both the OrderID and CustomerID are identical to another record are excluded from these results.
Example
Output
Explanation
The DISTINCTROW
keyword in the SQL command is used to fetch distinct or unique records. In the example provided, DISTINCTROW
is used to fetch unique Student_ID
and Name
from the table named Students
. As a result, any duplicate rows with the same combination of Student_ID
and Name
are removed from the returned result set.