• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 802
  • Last Modified:

Mysql Select distinct value from one column when selecting from two columns

I am using perl to script against mysql. I want to select two columns from a table and make sure that the only columns are returned that have distinct values in one of the columns.

select distinc column1, column2 from table;

This will return a distinct combination of the two colunms, wich is not what I want. For instance:
a 1
a 2
a 5
b 1
c 3

Every row above is distinct, but I want only rows that are distinct in the first column:
a 1
b 1
c 3

Is that possible, if so how?
0
itnifl
Asked:
itnifl
  • 2
1 Solution
 
fundacionrtsAdministrador de SistemasCommented:
If you always want the row that have second-column value lower, you can try

SELECT column1,MIN(column2) FROM table GROUP BY column1
0
 
itniflAuthor Commented:
I want to select dinstinctly based on the left column and not the right.
0
 
itniflAuthor Commented:
You were right, in my case it was:
SELECT MIN(column1),column2 FROM table GROUP BY column1
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Network Scalability - Handle Complex Environments

Monitor your entire network from a single platform. Free 30 Day Trial Now!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now