Differences between UNIQUE and DISTINCT in select statements
Answers were Sorted based on User's Feedback
Answer / kkparambath
SELECT DISTINCT Example
The "Persons" table:
P_Id LastName FirstName Address City
1 Hansen Ola Timoteivn10 Sandnes
2 Svendson Tove Borgvn 23 Sandnes
3 Pettersen Kari Storgt 20 Stavanger
Now we want to select only the distinct values from the
column named "City" from the table above.
We use the following SELECT statement:
SELECT DISTINCT City FROM Persons
The result-set will look like this:
City
Sandnes
Stavanger
| Is This Answer Correct ? | 7 Yes | 9 No |
Answer / chandrakant agrawal
Let us try one using :
select distinct dept_name
from departments;
What this query would return if dept_name column contains
NULL values.
| Is This Answer Correct ? | 3 Yes | 11 No |
Answer / satish parashar
After applying the unique clause all the value of column
will be sorted, But in distinct clause it only remove the
duplicacy from the table,not sorted the column value.
| Is This Answer Correct ? | 6 Yes | 15 No |
Answer / apparao akki
Hi all,
plz find the below executed report on the same.
------------------------------------------------------
SQL> select * from person;
PERSON_ID FIRST_NAME LAST_NAME
TITLE_1 TITLE_2 SOCS
---------- --------------------- -------------------------
---------- ---------- -----------
9 ssss rrrrr
tttt gggg 67778-3
1 THUUTHTUT lofstrom
ba null 4940-343
1 ffsdf fsdfsd
fdsfsd fsdf 5454
1 THUUTHTUT lofstrom
ba null 4940-343
1 THUUTHTUT lofstrom
ba null 4940-343
1 appa akki
s/w btech 3i
2 rao
s/w kmm 3i
4 bunny neel
lkg ukg home
8 rows selected.
SQL> select unique(person_id),last_name from person;
PERSON_ID LAST_NAME
---------- -------------------------
2
1 lofstrom
4 neel
1 fsdfsd
9 rrrrr
1 akki
6 rows selected.
SQL> select distinct(person_id) from person;
PERSON_ID
----------
4
9
2
1
| Is This Answer Correct ? | 9 Yes | 20 No |
Answer / vidya
unique allows null value but distinct does not consider
null value
| Is This Answer Correct ? | 2 Yes | 44 No |
what is SCALAR Queries?
What are the disadvantages of file system?
Can we insert data into view?
What are the uses of sysdate and user keywords?
what are the non-standard sql commands supported by 'mysql'? : Sql dba
display null value rows with out using null function?
i have a customer table. trans_id trans_date trans_amt debit_credit_indicator 001 01-JAN-13 1099 cr 001 12-JAN-13 500 db 002 24-FEB-13 400 db 002 23-MAR-13 345 cr 001 18-APR-13 800 cr 002 15-MAR-13 600 db 001 12-FEB-13 200 cr i want like this output. trans_id trans_amt debit_credit_indicator i want get highest credit amount and lowest credit amount and highest debit amount and lowest debit amount for each trans_id.
Is it possible to use LONG columns in WHERE clause or ORDER BY?
What is use of term?
what are the different tables present in mysql, which type of table is generated when we are creating a table in the following syntax: create table employee (eno int(2),ename varchar(10)) ? : Sql dba
What are different sql data types?
What is the difference between join and natural join?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)