I've a query which returns the following data
as you can see in the image the colored groups are similar regarding column "A" i want to take the first occurrence of these rows regarding column "A" and discard the rest.
so i can end up with this result.
any solutions?
Thanks :)
Update:
this is the original query results
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.
To get unique or distinct values of a column in MySQL Table, use the following SQL Query. SELECT DISTINCT(column_name) FROM your_table_name; You can select distinct values for one or more columns.
Answer. Yes, the DISTINCT clause can be applied to any valid SELECT query. It is important to note that DISTINCT will filter out all rows that are not unique in terms of all selected columns. Feel free to test this out in the editor to see what happens!
Yes, DISTINCT works on all combinations of column values for all columns in the SELECT clause.
I would do it as follows:
WITH T(A, B, C, D, RowNum) AS
(
SELECT A, B, C, D, ROW_NUMBER() OVER (PARTITION BY A ORDER BY A)
FROM MyTable
)
SELECT * FROM T
WHERE
RowNum = 1
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