I have a table like this (but with more columns):
Code Quantity ----- -------- 00001 1 00002 1 00002 1 00002 2 00003 2 00003 1
And I want to get the same result that with SELECT DISTINCT Code FROM table
(00001,00002,00003) but with all of the other table columns.
UPDATED: If I perform this: SELECT DISTINCT Code, Quantity from table
I get:
Code Quantity ----- -------- 00001 1 00002 1 00002 2 00003 1 00003 2
And I would like to get:
Code Quantity ----- -------- 00001 1 00002 1 00003 1
Thanks in advance!
Introduction to SQLite SELECT DISTINCT clause In this syntax: First, the DISTINCT clause must appear immediately after the SELECT keyword. Second, you place a column or a list of columns after the DISTINCT keyword. If you use one column, SQLite uses values in that column to evaluate the duplicate.
Adding the DISTINCT keyword to a SELECT query causes it to return only unique values for the specified column list so that duplicate rows are removed from the result set.
Yes, DISTINCT works on all combinations of column values for all columns in the SELECT clause.
Select with distinct on all columns of the first query. Select with distinct on multiple columns and order by clause. Count() function and select with distinct on multiple columns.
Assuming you are using MySQL (as the question is tagged), the following will return an arbitrary value for the other columns:
select * from t group by code;
However, the particular values being selected come from indeterminate rows.
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