[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SELECT DISTINCT on one column only

Posted on 2015-01-08
4
Medium Priority
?
117 Views
Last Modified: 2015-01-08
How do I select distinct only on one column.

Below is my current code...

$query_rs_media_new_group = "SELECT DISTINCT title, group_id, description, brand, weight, category, id FROM media_new";

Open in new window


My issue is that I need to select all the columns you see in my code. However I only want the "title" column to be DISTINCT.

What do I need to do?
0
Comment
Question by:petewinter
[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
  • 2
4 Comments
 
LVL 32

Expert Comment

by:Daniel Wilson
ID: 40538617
Would you provide some sample data and desired results?

Thanks!
0
 

Author Comment

by:petewinter
ID: 40538709
See sample data attached.

media-new.csv

You will notice in the data some of the "title" rows are the same. I only want to show the first unique "title".  So I should only see 8 of the 30 rows of data in the sample data.
0
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 2000 total points
ID: 40538772
You want each title but only one of each of the other fields.  OK, so we'll pick ... one of them.  We can pick the smallest or the largest.  If you want to switch to the largest, change the "MIN" to "MAX".
$query_rs_media_new_group = "SELECT title, MIN(group_id) as group_id, min(description) as description, min(brand) as brand, min(weight) as weight, min(category) as category, min(id) as id 
FROM media_new group by title";

Open in new window

0
 

Author Closing Comment

by:petewinter
ID: 40538840
Many thanks
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
In this article, we’ll look at how to deploy ProxySQL.
The viewer will learn how to count occurrences of each item in an array.
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…

649 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