Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,647 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,130 people online right now. Registration is fast and FREE... Join Now!




Select all unique values. . .

2 Pages V  1 2 >  
Reply to this topicStart new topic

Select all unique values. . .

The Neoracle
post 2 Dec, 2002 - 09:47 AM
Post #1


Check, check, 1, 2.

Group Icon
Joined: 30 Mar, 2001
Posts: 4,069



Thanked 1 times
My Contributions


How can I select all the values out of a MySQL Database that are UNIQUE. Say I have just random words in there and 1/2 of them have doubles, I want to return all of the values only once.

I'm not sure the SQL for this, how would I do this?
User is offlineProfile CardPM

Go to the top of the page

fyrestorm
post 2 Dec, 2002 - 08:19 PM
Post #2


D.I.C Lover

Group Icon
Joined: 4 Apr, 2002
Posts: 3,103



Thanked 2 times

Dream Kudos: 228
My Contributions


the only thing that pops into my head is that as you walk down your list to load them into an array and for each one you need to search the array to see if it's already in there and if it is don't add the new one...

i'm sure there's probably an easier way to do this, but this is all i can currently think of...
User is offlineProfile CardPM

Go to the top of the page

arniie
post 3 Dec, 2002 - 01:16 AM
Post #3


D.I.C Addict

****
Joined: 8 Oct, 2002
Posts: 999

i could be way off the mark (getting myself confused blink.gif )

but isn't GROUP BY exactly for this

ie

SELECT * FROM tablename GROUP BY fieldyouwantunique
User is offlineProfile CardPM

Go to the top of the page

MathewS
post 3 Dec, 2002 - 02:20 AM
Post #4


D.I.C Regular

***
Joined: 14 May, 2002
Posts: 252



Thanked 1 times

Dream Kudos: 1
My Contributions


I think this is what you are looking for.

CODE

$result = mysql_query("SELECT DISTICT fieldyouwantunique from tablename");
User is offlineProfile CardPM

Go to the top of the page

fyrestorm
post 3 Dec, 2002 - 07:31 AM
Post #5


D.I.C Lover

Group Icon
Joined: 4 Apr, 2002
Posts: 3,103



Thanked 2 times

Dream Kudos: 228
My Contributions


QUOTE(MathewS @ Dec 3 2002, 04:20 AM)
I think this is what you are looking for.

CODE

$result = mysql_query("SELECT DISTINCT fieldyouwantunique FROM tablename");

I knew there was an easier way, good going MatthewS
User is offlineProfile CardPM

Go to the top of the page

The Neoracle
post 3 Dec, 2002 - 09:51 AM
Post #6


Check, check, 1, 2.

Group Icon
Joined: 30 Mar, 2001
Posts: 4,069



Thanked 1 times
My Contributions


QUOTE(MathewS @ Dec 3 2002, 07:20 AM)
I think this is what you are looking for.

CODE

$result = mysql_query("SELECT DISTICT fieldyouwantunique from tablename");

My Hero.
User is offlineProfile CardPM

Go to the top of the page

The Neoracle
post 3 Dec, 2002 - 02:34 PM
Post #7


Check, check, 1, 2.

Group Icon
Joined: 30 Mar, 2001
Posts: 4,069



Thanked 1 times
My Contributions


Unknown column 'DISTICT' in 'field list'
User is offlineProfile CardPM

Go to the top of the page

arniie
post 3 Dec, 2002 - 02:50 PM
Post #8


D.I.C Addict

****
Joined: 8 Oct, 2002
Posts: 999

did you try my way?
User is offlineProfile CardPM

Go to the top of the page

The Neoracle
post 3 Dec, 2002 - 03:47 PM
Post #9


Check, check, 1, 2.

Group Icon
Joined: 30 Mar, 2001
Posts: 4,069



Thanked 1 times
My Contributions


QUOTE(arniie @ Dec 3 2002, 07:50 PM)
did you try my way?

That's just going to order them with all the same ones together, that's how they already are.
User is offlineProfile CardPM

Go to the top of the page

skrilla
post 3 Dec, 2002 - 06:38 PM
Post #10


boots.

*****
Joined: 5 Jul, 2002
Posts: 2,848



Dream Kudos: 14
My Contributions


dude, its a typo. use this (its what he meant) ::

CODE
$result = mysql_query("SELECT DISTINCT fieldyouwantunique FROM tablename");


-pete
User is offlineProfile CardPM

Go to the top of the page

The Neoracle
post 3 Dec, 2002 - 07:44 PM
Post #11


Check, check, 1, 2.

Group Icon
Joined: 30 Mar, 2001
Posts: 4,069



Thanked 1 times
My Contributions


QUOTE(skrilla @ Dec 3 2002, 11:38 PM)
dude, its a typo. use this (its what he meant) ::

CODE
$result = mysql_query("SELECT DISTINCT fieldyouwantunique FROM tablename");


-pete

Fucking spelling.
User is offlineProfile CardPM

Go to the top of the page

Cookie Mobster
post 3 Dec, 2002 - 07:48 PM
Post #12


nooneenooneenooonee

Group Icon
Joined: 12 Oct, 2001
Posts: 4,723



Dream Kudos: 18
My Contributions


* Note: SELECT DISTINCT will not work properly with JOINED tables.
User is offlineProfile CardPM

Go to the top of the page

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 04:54AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month