SQL DISTINCT

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

SQL DISTINCT

Post by aceconcepts »

Hi,

I am trying to display a list of products ordered using php and mysql.

I want to be able to display a list of all product orders but not each individual product.

I am retrieving data from more than one table.

Can I do this by using DISTINCT? if so, how?

Thanks
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

What have you tried? Can we see your tables?
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Post by aceconcepts »

A better way of describing what I am trying to do is:

Can i use DISTINCT as follows -

Code: Select all

"SELECT * DICSTINCT product_id";
I want to select all fields but use distinct on just one of those fields.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

you'd probably be better off using a GROUP BY clause and just grouping by the the one you want distinct.
Post Reply