?
Solved

SELECT DISTINCT on one column only

Posted on 2015-01-08
4
Medium Priority
?
110 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

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

752 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