Solved

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

Posted on 2012-03-11
3
745 Views
Last Modified: 2012-03-11
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
Comment
Question by:itnifl
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
fundacionrts earned 500 total points
ID: 37707735
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
 
LVL 2

Author Comment

by:itnifl
ID: 37708495
I want to select dinstinctly based on the left column and not the right.
0
 
LVL 2

Author Closing Comment

by:itnifl
ID: 37708504
You were right, in my case it was:
SELECT MIN(column1),column2 FROM table GROUP BY column1
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now