Solved

SELECT DISTINCT on one column only

Posted on 2015-01-08
4
92 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
  • 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 500 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

937 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now