COUNT(*) function returns the number of items in a group, including NULL and duplicate values. In that case they aren't synonymous and 'unique' would be wrong if the input weren't alread Second option is listagg(), but it has limited length and you should use separators not appearing in values. DISTINCT for multiple columns is not supported. ... select count(*) from ( select distinct a,b,c from t ) Rating (1 rating) ... free access to the latest version of Oracle Database! Do you need anithing else? ... select count(*) from ( select distinct a,b,c from t ) Rating (1 rating) ... free access to the latest version of Oracle Database! Our query looks like this: I would like to select all students that have been passed semester 1 and 4, with my query it shows only one row by student, I was expecting two.. The Oracle DISTINCT qualifier affects all selected columns, in so doing, the result will display the unique combination of values from the different columns. For example :- I have a table tab1 having primary key on col_pk. Note: The Oracle DISTINCT keyword should be included immediately after the Oracle SELECT keyword.. Oracle DISTINCT Statement on Multiple Columns. The following will make all three columns distinct. In this query we start by selecting the distinct values for all columns. It's a never-ending source of wonder for me how so many people (not you!) Yes, DISTINCT works on all combinations of column values for all columns in the SELECT clause. I am writing a messageboard/forum and have a database with these columns: PostSubject ThreadID PostID (unique identifier) Multiple messageboard posts can have the same ThreadID, such as replies to a post. The ORDER BY clause allows you to sort data by multiple columns where each column may have different sort orders. If you want to select distinct values of some columns in the select list, you should use the GROUP BY clause.. I've updated my example. In this query, T1 is the left table and T2 is the right table. Classes, workouts and quizzes on Oracle Database technologies. COUNT() function and SELECT with DISTINCT on multiple columns. COUNT(*) function returns the number of items in a group, including NULL and duplicate values. The Oracle DISTINCT qualifier affects all selected columns, in so doing, the result will display the unique combination of values from the different columns. COUNT(ALL expression) evaluates the expression and returns the number of non-null items in a group, including duplicate values. SELECT *, p.name AS name, p.image, p.price, unpack((select PACK (CCSID 1028, ps.price, ps.date) FROM product_special ps WHERE p.id = ps.id AND ps.date < NOW() ORDER BY ps.priority ASC, LIMIT 1)) . How to count distinct values over multiple columns using SQL. By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy. The SQL SELECT DISTINCT Statement. SQL> SELECT DISTINCT LOCATION_ID FROM HR.DEPARTMENTS; LOCATION_ID ----- 1800 2400 1400 2500 1700 2700 1500 7 rows selected. The DISTINCT keyword eliminates duplicate records from the results. @DaveesJohnBaclay my query does exactly what you are asking for. The query compares each row in the T1 table with rows in the T2 table.. site design / logo © 2021 Stack Exchange Inc; user contributions licensed under cc by-sa. I've been trying to find a way, using Oracle Express, to return more than one column but have only one column be distinct. I've seen queries like this: SELECT DISTINCT(T1.id), T2.id, T2.amt FROM T1 … The SELECT DISTINCT statement is used to return only distinct (different) values. Often we want to count the number of distinct items from this table but the distinct is over multiple columns. WHERE conditions Optional. SQL Server SELECT DISTINCT - multiple columns example before. It operates on a single column. Copyright ©document.write(new Date().getFullYear()); All Rights Reserved, Cannot assign value of type cgaffinetransform to type catransform3d, How to remove duplicates from array in java using collections, How to round off the values of a particular field in the data frame. When used with multiple columns the combined value of all those columns collectively is … Posted December 29, 2020 by. tables The tables that you wish to retrieve records from. Dev Gym. Active 3 years, 10 months ago. Join Stack Overflow to learn, share knowledge, and build your career. The columns are: tblFruit_ID, tblFruit_FruitType, tblFruit_FruitName int NVarChar Text I am trying to select all the tblFruit_FruitType with their corresponding tblFruit_ID. I need to find distinct values in a table based on 3 columns. The following will make all three columns distinct. To accomplish this, we’ll need to select the entire table and join that to our duplicate rows. select unique vs. select distinct Can you please settle an argument we are having re: 'select unique' vs. 'select distinct'? Oracle ORDER BY clause examples. Distinct values based on multiple columns ‎07-13-2017 07:01 AM. What is special about the area 30 km west of Beijing? Can this be done in Oracle? 5. It must evaluate to a built-in numeric data type. Ask Question Asked 5 years, 8 months ago. However, one other important point is that a tuple is counted only if none of the individual values in the tuple is null. First year Math PhD student; My problem solving skill has been completely atrophied and continues to decline. Thanks for contributing an answer to Stack Overflow! count of distinct on multiple columns does not work; Breadcrumb. Now the count will be 2 for 123456 and 1 for everyone else? COUNT() function and SELECT with DISTINCT on multiple columns. The syntax for the DISTINCT clause in Oracle/PLSQL is: SELECT DISTINCT expressions FROM tables [WHERE conditions]; Parameters or Arguments expressions The columns or calculations that you wish to retrieve. SQL> You can use DISTINCT for multiple columns as follows. COUNT(ALL expression) evaluates the expression and returns the number of non-null items in a group, including duplicate values. Thanks Much, Lewis The SQL Distinct keyword will not ignore any NULL values from query result. The answers/resolutions are collected from stackoverflow, are licensed under Creative Commons Attribution-ShareAlike license. It operates on a single column. DISTINCT can be used with aggregates: COUNT, AVG, MAX, etc. SELECT DISTINCT on one column, with multiple columns returned. * You can use an order by clause in the select statement with distinct on multiple columns. By now we have discussed what is a DISTINCT keyword in oracle, the syntax of DISTINCT keyword and the various parameters used in the syntax. Dev Gym. Asking for help, clarification, or responding to other answers. So both these rows to be listed in output. a step function. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. the objective is to get the uniqueness even on multiple columns. about his research, and about courses that deal with his specialty/my career goal? What happens if I negatively answer the court oath regarding the truth? SELECT DISTINCT returns only distinct (i.e. Here is an example: SQL Code: SELECT DISTINCT agent_code,ord_amount FROM orders WHERE agent_code='A002' ORDER BY ord_amount; Output: If that last aspect of the behaviour is what you are trying to achieve, you could emulate it using a conditional inside COUNT. "OR"? Specify the object name followed by a period and the asterisk to select all columns from the specified table, view, or materialized view. Who can use "LEGO Official Store" for an online LEGO store? The DISTINCT keyword applies to the entire result set, so adding DISTINCT to your query with multiple columns will find unique results. In the previous step, our query returned a list of duplicates. Thanks Tom. The best candidate for this unique column is the primary key column or a column with unique index (single column) or composite unique index (multiple columns) defined. SELECT DISTINCT eliminates duplicate rows from the table. In other words, the DISTINCT clause treats all NULL “values” as the same value. Thanks and Regards Krithika SELECT DISTINCT on one column, with m You can use an order by clause in the select statement with distinct on multiple columns. The COUNT() function accepts a clause which can be either ALL, DISTINCT, or *:. The syntax of distinct in SQL is given below-Distinct in SQL Syntax. You can use count() function in a select statement with distinct on multiple columns to count the distinct rows. This clause can be used on single or multiple columns. Because we specified both bcolor and fcolor columns in the SELECT DISTINCT clause, PostgreSQL combined the values in both bcolor and fcolor columns to evaluate the uniqueness of the rows.. Query multiple columns into one row I have the following senario of a an address table where each id has at least one address or more. I have a problem with distinct my query is "select distinct code and ID from tbl1" Code id 1 2 1 3 In this I will get count as 2.But I want ID's for distinct codes that is my record count should be only one. ... You can select all 3 columns, then click 'Group By' and create a new Count Rows column. count of distinct on multiple columns does not work; Breadcrumb. You can use an order by clause in the select statement with distinct on multiple columns. SELECT with DISTINCT on multiple columns and ORDER BY clause. I've a csv file which contains data with new lines for a single row i.e. You solution for duplicates considers (123,456) and (123,999) as duplicates, Still wrong: check again, now with (123,456) and (999,123), I followed my dreams and got demoted to software developer, Opt-in alpha test for a new Stacks editor, Visual design changes to the review queues, Select columns from result set of stored procedure. Thanks for the question, Rajneesh. How to keep right color temperature if I edit photos with night light mode turned on? I've been trying to find a way, using Oracle Express, to return more than one column but have only one column be distinct. But rows 2 and 4 has unique combination for first 3 columns but they have same values in DEF column.So not to be listed in output. different) values. In the previous tutorial we learned how to use SQL DISTINCT statement in Oracle database. Filtering a List based on a Suffix and avoid duplicates, How to connect mix RGB with Noise Texture nodes. Why do some PCB designers put pull-up resistors on pins where there is already an internal pull-up? How can I achieve this to Select to one row only dynamically since your coworkers to find and share information. Could I use a blast chiller to make modern frozen meals at home? Method-1 Using a derived table (subquery) You can simply create a select distinct query and wrap it inside of a select count(*) sql, like shown below: SELECT COUNT(*) Sql select unique values from multiple columns. Sql select unique values from multiple columns. DISTINCT can be used with aggregates functions like COUNT, AVG, MAX, etc. You can use count() function in a select statement with distinct on multiple columns to count the distinct rows. SELECT DISTINCT Job_ID, Employee_ID, Last_Name FROM Employees ORDER BY Last_Name. Otherwise, multiple records may exist for each customer. Next, we issue SQL*plus breaks to get only the distinct values for every column in the result set: select deptno, loc, job, sal, ename from lsc_emp join lsc_dept using (deptno) order by deptno,loc,job,sal,ename; Why won't the top three strings change pitch. Prior to Oracle Database 11g, you would do that via some sort of a decode function for each value and write each distinct value as a separate column.The technique is quite nonintuitive however. The advantage is that you can select other columns in the result as well (besides the key and value) :. The syntax for the DISTINCT clause in Oracle/PLSQL is: SELECT DISTINCT expressions FROM tables [WHERE conditions]; Parameters or Arguments expressions The columns or calculations that you wish to retrieve. Asking a faculty member at my university that I have not met(!) Below is an example shows how non-unique columns are used that produce duplicate records in the result. Before we move into the examples, we will use the EMPLOYEE table already created in the database. Example: In the below example first two rows has same value for first 3 columns.But they have different value for column DEF. The Oracle docs say they are synonymous, but it seems to imply that 'distinct' forces a sort where 'unique' does not. Can anyone plsss help. SELECT key, value FROM tableX ( SELECT key, value, ROW_NUMBER() OVER (PARTITION BY key ORDER BY whatever) --- ORDER BY NULL AS rn --- for example FROM tableX ) tmp WHERE rn = 1 ; Oracle SELECT DISTINCT By Practical Examples, in the column_1 , column_2 , and column_3 are used to determine the uniqueness of the data. DISTINCT for multiple columns is not supported. How to select only the first rows for each unique value of a column? You can use DISTINCT on multiple columns. The issue is with this line . Generating random samples obeying the exponential distribution with a given min and max. Thanks Much, Lewis Can this be done in Oracle? It's a never-ending source of wonder for me how so many people (not you!) Dim sql2 = "SELECT DISTINCT " & Field1 & " INTO NewTable " & " from " & TableName Here is an example: SELECT COUNT(*) FROM ( SELECT DISTINCT agent_code, ord_amount,cust_code FROM orders WHERE agent_code='A002'); Output: Advanced Oracle SQL Programming?. I need to have DISTINCT values for one column, however I also need the rest of the data associated with it.. My SQL code: SELECT acss_lookup.ID AS acss_lookupID, acss_lookup.product_lookupID AS acssproduct_lookupID, acss_lookup.region_lookupID AS acssregion_lookupID, acss_lookup.document_lookupID AS … SQL> SELECT DISTINCT LOCATION_ID FROM HR.DEPARTMENTS; LOCATION_ID ----- 1800 2400 1400 2500 1700 2700 1500 7 rows selected. It removes all the duplicate records from query results while fetching data from table.. I've seen queries like this: SELECT DISTINCT(T1.id), T2.id, T2.amt FROM T1 JOIN T2 ON T2.T1id = T1.id Count() function and select with distinct on multiple columns. for how to do this in Oracle. SELECT DISTINCT last_name, active FROM customer; Re: DISTINCT: single vs multiple columns L. Fernigrini Sep 30, 2019 3:20 PM ( in response to eeps ) Yes, DISTINCT affects all the data being returned, as John show you. DISTINCT for multiple columns is not supported. List All Rows Containing Duplicates. The exact code depends on Oracle version. I need to select one of each version in the data (using the code field) while keeping all the columns in the final output. I've loaded the data into sql but now I want to replace the second row data into 1st row with respective column values. I have a query which uses three lookup tables to get all the information I need. Note: The Oracle DISTINCT keyword should be included immediately after the Oracle SELECT keyword.. Oracle DISTINCT Statement on Multiple Columns. Classes, workouts and quizzes on Oracle Database technologies. tables The tables that you wish to retrieve records from. Part 9 in a series on the basics of the relational database and SQL By Melanie Caffrey . I need to write a query in plsql to select records for first 3 distinct values of a single column (below example, ID )and all the rows for next 3 distinct values of the column and so on till the end of count of distinct values of a column. The Expression can contain multiple column references or expressions, but it cannot contain another aggregate or subquery. You can use the count() function in a select statement with distinct on multiple columns to count the distinct rows. Is there a way to get distinct values for multiple columns? We will use the customers table in the sample database for demonstration. Here is an example : SQL Query Multiple Columns Using Distinct on One Column Only , select * from tblFruit where tblFruit_ID in (Select max(tblFruit_ID) FROM tblFruit group by tblFruit_FruitType). There must be at least one table listed in the FROM clause. But If you use DISTINCT, then you can display only unique or distinct values as follows. How do I limit the number of rows returned by an Oracle query after ordering? SQL> You can use DISTINCT for multiple columns as follows. Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values. It can filter only unique data for a single column value or an entire records from query result.. WHERE conditions Optional. Sep 14, 2009 01:01 AM | invervegas | LINK. Interest: what is the most strategic time to make a purchase: just before or just after the statement comes out? Select DISTINCT returns only distinct (different) values from the table. select distinct on (a.personalId, a.fileId) a.personalId, a.fileId, a.name, a.surname, a.address from my_table a See Oracle equivalent of Postgres' DISTINCT ON? Listing 8 shows a query that determines the count of DISTINCT or UNIQUE (a keyword you can use instead of DISTINCT) MANAGER column values in the EMPLOYEE table. one row data comes in two lines and I want to insert the new lines data into respective columns. COUNT(DISTINCT expression) function returns the number of unique and non-null items in a group. oracle select distinct values from multiple columns. What causes \r's to be inserted before \n's when retrieving a binary file over ssh, and how do I circumvent it? Stack Overflow for Teams is a private, secure spot for you and SQL SELECT DISTINCT Statement How do I return unique values in SQL? SELECT DISTINCT Job_ID, Employee_ID, Last_Name FROM Employees ORDER BY Last_Name. It returns unique pairs. I have tried: SQL SELECT with DISTINCT on multiple columns, How can I extract unique values among all columns for each column throughout the table but not just inside of a column? You can use count() function in a select statement with distinct on multiple columns to count the distinct rows. The DISTINCT clause is used to retrieve the unique of different values of the columns of the table that contain duplicate values in their column. Why do trees break at the same wind speed? For other DBMSs, that have window functions (like Postgres, SQL-Server, Oracle, DB2), you can use them like this. Thanks for the question, Rajneesh. Supposing we have a table with four columns (a,b,c,d) of the same data type. After the Oracle DISTINCT keyword, it is possible to specify more than one column. But If you use DISTINCT, then you can display only unique or distinct values as follows. The SQL SELECT DISTINCT keyword is used to fetch only unique (without duplicates) values or records.. To retrieve unique data based on multiple columns, you just need to specify the column list in the SELECT clause as follows: SELECT DISTINCT column_1, column_2, column_3 FROM table_name; In this syntax, the combination of values in the column_1, column_2, and column_3 are used to determine the uniqueness of the data. zaiste.net, to determine the uniqueness of the row in the result set. In this case you have several options, for example you can unpivot values, sort, pivot and take unique values. In this query we start by selecting the distinct values for all columns. To learn more, see our tips on writing great answers. Next, we issue SQL*plus breaks to get only the distinct values for every column in the result set: select deptno, loc, job, sal, ename from lsc_emp join lsc_dept using (deptno) order by deptno,loc,job,sal,ename; different) values. I can illustrate the issue with an example as below:Assume there is a stock table with the structure:create table TEST_STOCK (item_id number, location_id number, QUANTITY numb If the columns were used in multiple WHERE-clause combinations, I index each one of the columns that are being used. Question and Answer. I want only the Job_ID column to be distinct. Should I use DATE or VARCHAR in storing dates in MySQL? You can use an order by clause in the select statement with distinct on multiple columns. SELECT Student.mat_stud, fname, lname, dbirth, materials_notes, semester FROM Student, Notes WHERE Notes.mat_stud = Student.mat_stud AND fails_status = 1 AND Notes.mat_div = 1 AND semester IN(1 , 4) AND Notes.level = 1 AND school_year = 2015 Group By. Making statements based on opinion; back them up with references or personal experience. Riemann-Stieltjes integral of a continuous function w.r.t. January/February 2013. Get all unique values in a JavaScript array (remove duplicates). Another option is to compare data as collections. Thanks for the question, Rajneesh. Now we will look into various examples to learn how to efficiently use DISTINCT in Oracle. Now, we want to return the entire record for each duplicate row. Re: DISTINCT: single vs multiple columns L. Fernigrini Sep 30, 2019 3:20 PM ( in response to eeps ) Yes, DISTINCT affects all the data being returned, as John show you. Advanced Oracle SQL Programming?. SELECT distinct agent_code,ord_amount FROM orders WHERE agent_code='A002' order by ord_amount; Output: Count() function and select with distinct on multiple columns. You need to add coalesce on greatest too. I need to return two columns, just to treat that the 2 rows are equal, (T2.COLA = T1.COLA OR T2.COLA = T1.COLB) ? In addition to that here in this tutorial I have explained short and crisp process of using SELECT DISTINCT statement when you have more than one columns. Viewed 83k times 23. Question and Answer. SQL SELECT DISTINCT Statement How do I return unique values in SQL? The null value that exists in the MANAGER column for several employees is not included in the count of distinct manager values by the call to the COUNT aggregate function. I am trying to write a SQL query that selects multiple columns from a table with the distinct operator on one column only. Classes, workouts and quizzes on Oracle Database technologies. think that DISTINCT applies only to one column. Code language: SQL (Structured Query Language) (sql) The query uses the combination of values in all specified columns in the SELECT list to evaluate the uniqueness.. select group_concat(column_name) from information_schema.columns where table_schema = 'computers' and table_name='laptop' and column_name not in ('code') order by ordinal_position; It should be mentioned that the information schema in MySQL covers all database server, not certain databases. Question and Answer. After the Oracle DISTINCT keyword, it is possible to specify more than one column. Note that the ORDER BY clause is always the last clause in a SELECT statement. In DB2 for z/OS, use pack and unpack functions to return multiple columns in a subselect. The query returns the unique combination of bcolor and fcolor from the distinct_demo table.Notice that the distinct_demo table has two rows with red value in both bcolor and fcolor columns. count of distinct on multiple columns does not work; Breadcrumb. How do I cite my own PhD dissertation in a journal article? Multiset except does main job: dbfiddle with 3-column table, nulls and different test cases. SELECT DISTINCT returns only distinct (i.e. If you apply the DISTINCT clause to a column that has NULL, the DISTINCT clause will keep only one NULL and eliminates the other. Select distinct on multiple columns View as plain text Hi everyone, I am using PHP4 RC1and MySQL 3.22.32 and have a table with 5 columns (and the usual ID, etc): CAT_1 CAT_2 CAT_3 CAT_4 CAT_5 They are categories, selected from drop down menus, used to select the categories a product fits into. ... select count(*) from ( select distinct a,b,c from t ) and you rated our response (1 rating) ... free access to the latest version of Oracle Database! You can use the count() function in a select statement with distinct on multiple columns to count the distinct rows. SELECT AVG (DISTINCT flying_time), SUM (DISTINCT miles) FROM Flights. SELECT with DISTINCT on multiple columns and ORDER BY clause. Oracle SELECT DISTINCT By Practical Examples, in the column_1 , column_2 , and column_3 are used to determine the uniqueness of the data. There must be at least one table listed in the FROM clause. Here I used dbms_debug_vc2coll which is simple table of varchars. SELECT DISTINCT ON MULTIPLE COLUMNS, SPECIFY COLUMNS TO BE RETAINED Posted 02-10-2015 12:19 PM (55365 views) This is a simple question : I want to create a table selecting distinct observations from an existing table based on combination of three columns but I want to retain some more variables from the original table. DISTINCT can be used with aggregates: COUNT, AVG, MAX, etc. In Excel there is a great  SELECT with DISTINCT on multiple columns and ORDER BY clause. To retrieve unique data based on multiple columns, you just need to specify the column list in the SELECT clause as follows: SELECT DISTINCT column_1, column_2, column_3 FROM table_name; In this syntax, the combination of values in the column_1, column_2, and column_3 are used to determine the uniqueness of the data. I am selecting distinct on a code field but I cannot figure how to return the rest of the columns. I’ve also included practical examples to aid better understanding of the concept. If an expression evaluates to … Count() function and select with distinct on multiple columns. SELECT DISTINCT on one column, with multiple columns returned [Answered] RSS 3 replies Last post Sep 15, 2009 03:30 AM by invervegas. Term for people who believe God once existed but then disappeared? think that DISTINCT applies only to one column. Here is an example: SQL Code: SELECT DISTINCT agent_code,ord_amount FROM orders WHERE agent_code='A002' ORDER BY ord_amount; Output: SQL Server SELECT DISTINCT, Sometimes, you may want to get only distinct values in a specified column of a table. The COUNT() function accepts a clause which can be either ALL, DISTINCT, or *:. If you want to find the duplicate then use the EXISTS as follows: If I correctly understand words: objective is to get the uniqueness even on multiple columns, number of columns may vary, table can contain 2, 3 or more columns. SELECT DISTINCT on multiple columns. Yes, DISTINCT works on all combinations of column values for all columns in the SELECT clause. EXISTS (SELECT 1 from EMP_TEST WHERE TS.item_id in (select 1 from DUAL union select 2 from DUAL)) With the above EXISTS clause, the value of SUM_QUANTITY column in multiplied by the number of records in EMP_TEST table. SQL DISTINCT on Multiple Columns. Is it good practice to echo PHP code into inline JS? Dev Gym. SELECT with DISTINCT on multiple columns and ORDER BY clause. Fortunately, you now have a great new feature called PIVOT for presenting any query in the crosstab format using a new operator, appropriately named pivot. The table consists of five columns which are NAME, VEHICLE_NAME, EMPLOYEE_ID, VEHICLE_ID… COUNT(DISTINCT expression) function returns the number of unique and non-null items in a group. ID Name Department DOB State Country Salary. How do I UPDATE from a SELECT in SQL Server? SUM OVER PARTITION BY with a DISTINCT in the SELECT clause gives unexpected results Hi Tom,We see a very strange issue with SUM OVER PARTITION BY statements when there is DISTINCT clause in the query. Unique on a dataframe with only selected columns, Selecting multiple columns in a Pandas dataframe, In Postgresql, force unique on combination of two columns. Postgresql supports the DISTINCT ON syntax: http://www.postgresql.org/docs/current/interactive/sql-select.html. If a pair of rows from both T1 and T2 tables satisfy the join predicate, the query combines column values from rows in both tables and includes this row in the result set.. So, if the number of reords in EMP_TEST table is 6, then the column shows a value of 60. Part 8 in this series, “Selecting a Type That Is Right for You” (Oracle Magazine, November/December 2012), introduced common SQL date functions and showed how your queries can use them to modify the appearance of date result set data.It also introduced the SYSDATE function … The DISTINCT keyword eliminates duplicate records from the results. I want only the Job_ID column to be distinct. Distinct on few columns in table and return columns not part of distinct Tom and team,I think i goofed up with my question submission, sorry about that.Attempting to write again by trying to put the question through new perspective - I have a need to query certain people out of a table by looking at only subset of the columns in the table.If we include the co select colA from your_table union select colB from your_table; Update: If you want to find the duplicate then use the EXISTS as follows: SELECT COLA, COLB FROM YOUR_TABLE T1 WHERE EXISTS (SELECT 1 FROM YOUR_tABLE T2 WHERE T2.COLA = T1.COLB OR T2.COLB = T1.COLA)  The table is simple. A count of 3 is returned. Obviously, COUNT(DISTINCT) with multiple columns counts unique combinations of the specified columns' values. rev 2021.2.9.38523, Stack Overflow works best with JavaScript enabled, Where developers & technologists share private knowledge with coworkers, Programming & related technical career opportunities, Recruit tech talent & build your employer brand, Reach developers & technologists worldwide, What if you have a multiple rows and you just want to get the unique values, This solution will not work if one of the column value is null as least and greatest will give you null if one of the column value is null, @Tejash that's pretty easy - just add coalesce.