Selecting unique records from database table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

Selecting unique records from database table

Post by michlcamp »

I have a data table called 'orders' where customer history is posted and want to pull only unique email address from the table.

I'm starting with query:

Code: Select all

$sql="SELECT email FROM orders ORDER  ASC";
do I use the 'unique' or operator?

thanks in advance...learning slowly but sure...
mc
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

DISTINCT keyword is what you are looking for.
janson0
Forum Newbie
Posts: 6
Joined: Thu Jun 01, 2006 11:10 am

Post by janson0 »

I think you can do something like:

Code: Select all

$sql = SELECT DISTINCT email FROM orders;
Try that

Good luck!
-Michael
Post Reply