Solved

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

Posted on 2012-03-11
3
755 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Creating and Managing Databases with phpMyAdmin in cPanel.
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…

808 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