How I fetch values from one column based on distinct values from other column?

zee

I have two columns in a table and I want a query to fetch First column values based on distinct values from Second column. Since, There are multiple combinations of First and second column I would like to have the first match from each combination.

DATASET:

First Column Second Column
A abc
B abc
C abc
D abc
F abc
G abc
H qwe
I qwe
J jkl
K jkl
L jkl
M uio
N uio

Excepted Output:

First Column Second Column
A abc
H qwe
J jkl
M uio
Barmar

Just use MIN() and GROUP BY.

SELECT min(`First Column`) AS `First Column`, `Second Column`
FROM yourTable
GROUP BY `Second Column`

DEMO

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Rolling over values from one column to other based on another dataframe

How can I create a new column of values based on the grouped sum of values from two other columns?

Distinct values from an ARRAY column

Summing up values from one column based on values in other column

MySQL - count distinct values from one column based on another column

Select distinct values from a column based on highest value in another column

How to extract unique values from one column based on criteria from two other columns, with or statement?

MySQL: Select distinct values from one column if other column has two determined values in junction table

Get values from a column based on other column

SQL - How to add a calculated column based on values from other columns

Hive: randomly select N values from distinct values of one column

How to shift one column, based on values from another column?

How to recreate new columns with column names from one column & column values from the other

How to filter for value in one column based on values from other columns in R?

Fetch values from one column of a table with PDO

In Postgresql, how can I fetch an unknown # of records from a table that have M distinct values in one column?

Counting Values based on distinct values from another Column

How to sort the values in one column based on other column values?

How to move values from one column to another based on matching values from other columns

List values from one column not found in the other

php,sql - how to alter values from one column and inserting it into other

How to Copy Data From Other Column Based On Other Cloumn Values

How to extract values from column based on string value in other column?

How do I show distinct values from one column along with one of it's corresponding rows?

How do you pull data from one sheet to 3 other sheets based on specific column values?

How to count values from one column based on the description in other column in pandas?

Power BI - How do I append two columns from two tables into one column with distinct values

How to find the number of distinct values from one column for a group of values from another column in DAX

How to add a column which does a string addition of values from other column based on condition from another column