Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between select distinct id and select distinct * in sql

i tried with

select distinct ID  from  DB.TABLE;

it returned unique ids in all records.

select distinct *  from  DB.TABLE;

it will return unique records by comparing all columns and records or what is functionality of "distinct *" ,i confused with functionality of distinct * .

like image 459
Ahito Avatar asked Feb 19 '26 08:02

Ahito


1 Answers

DISTINCT means that there will be no duplicate rows in the resultset, duplicate meaning all columns have the same value in both rows. So yes, DISTINCT * means "select all columns and skip any rows where the values in all columns match some already included row".

like image 84
Jiri Tousek Avatar answered Feb 21 '26 20:02

Jiri Tousek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!