Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2012-03-11
3
Medium Priority
?
777 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
fundacionrts earned 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

718 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