Oracle Sql Select Distinct Example
The SQL SELECT DISTINCT Statement. The SELECT DISTINCT statement is used to return only distinct different values. SELECT Example Without DISTINCT. If you omit the DISTINCT keyword, the SQL statement returns the quotCountryquot value from all the records of the quotCustomersquot table
For example SELECT DISTINCT city, state FROM customers WHERE total_orders gt 10 ORDER BY city This Oracle DISTINCT clause example would return each unique city and state combination from the customers table where the total_orders is greater than 10. The results are sorted in ascending order by city. In this case, the DISTINCT applies to each
Syntax and Examples. The syntax for SELECT DISTINCT is simple SELECT DISTINCT column1, column2, column3, FROM table_name ANSI SQL defines the DISTINCT clause, so it's supported across all major databases like PostgreSQL, MySQL, SQL Server, etc. We've covered a lot of ground around using SELECT DISTINCT in Oracle. Here are the
The Oracle DISTINCT keyword in the SELECT clause is used to eliminate duplicate rows and display a unique list of values. For example let us assume we have a Customers table, which contains a list of customers from different cities 40 customers from London, 30 from Liverpool and 30 from Manchester.
SQLgt select distinct deptno, job from emp order by empno select distinct deptno, job from emp order by empno ERROR at line 1 ORA-01791 not a SELECTed expression SQLgt It won't work as you already know. But, if you use a subquery or a CTE, then you get this
Let's see another example SELECT DISTINCT department_id, name FROM employee Results DEPARTMENT_ID NAME 1 JOHN SMITH 4 LUKE MINT 3 IGOR KEYS OSBOURNE 1 ANGIE CROOD 1 EDDIE FARREL 2 GEORGE HAYES 4 The truth is, that even though almost no one uses it, UNIQUE is a correct SQL keyword in Oracle, and it is equivalent to
In this example, the DISTINCT operator uses both values in the product_id and quantity columns to evaluate the uniqueness of the rows in the result set.. Oracle SELECT DISTINCT and NULL . In Oracle, NULL represents unknown data. Therefore, a NULL is different from another. However, the DISTINCT treats NULL differently.. If you use the SELECT DISTINCT operator to retrieve data from a column
The SELECT DISTINCT statement in Oracle SQL is used to retrieve unique values from a specified column or a combination of columns in a table. It eliminates duplicate rows from the result set and returns only distinct values. In this example, the statement retrieves unique values from the quotcountryquot column of the quotcustomersquot table.
Here we discuss DISTINCT keyword in oracle, the syntaxes used for using DISTINCT in codes and output. SELECT from employee On executing in SQL developer we get all the values as shown below. Unique Values in a Column without Condition. In this example, we are going to use DISTINCT to find the unique values in a particular column of a
But If you use DISTINCT, then you can display only unique or distinct values as follows. SQLgt SELECT DISTINCT LOCATION_ID FROM HR.DEPARTMENTS LOCATION_ID ----- 1800 2400 1400 2500 1700 2700 1500 7 rows selected. SQLgt You can use DISTINCT for multiple columns as follows.