Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL Distinct on multiple columns

Posted on 2008-06-23
3
Medium Priority
?
1,910 Views
Last Modified: 2008-07-14
I want to get the distinct set of rows based on the uniqueness of multiple columns

ex: I have a table last,first whose data is:

smith, john
smith, john
smith, fred

i want to run SQ - something similar to:
select distinct last,first from table;

should return:
smith,john
smith,fred
0
Comment
Question by:pmsguy
3 Comments
 
LVL 4

Accepted Solution

by:
zx10r earned 750 total points
ID: 21850986
why don't you just use GROUP BY
0
 
LVL 17

Expert Comment

by:HuyBD
ID: 21852842
Could you explain more
0
 
LVL 28

Assisted Solution

by:gamebits
gamebits earned 750 total points
ID: 21884112
In your example a simple distinct clause will return what you are looking for, would be different though if you add a third column

smith, john, 1
smith, john, 2
smith, fred, 1

Then a distinct query would return all three of them.
0

Featured Post

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Recursive SQL is one of the most fascinating and powerful and yet dangerous feature offered in many modern databases today using a Common Table Expression (CTE) first introduced in the ANSI SQL 99 standard. The first implementations of CTE began ap…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

773 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