When I perform SELECT * FROM table
I got results like below:
1 item1 data1 2 item1 data2 3 item2 data3 4 item3 data4
As you can see, there are dup records from column2 (item1 are dupped). So how could I just get result like this:
1 item1 data1 2 item2 data3 3 item3 data4
Only one record are returned from the duplicate, along with the rest of the unique records.
DISTINCT or UNIQUE keyword in SQL is used with SELECT statement/query to select only unique records from a table, i.e. it eliminates all duplicate records from a table.
If you want the query to return only unique rows, use the keyword DISTINCT after SELECT . DISTINCT can be used to fetch unique rows from one or more columns. You need to list the columns after the DISTINCT keyword.
With the distinct
keyword with single and multiple column names, you get distinct records:
SELECT DISTINCT column 1, column 2, ... FROM table_name;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With