12 Replies - 15494 Views - Last Post: 04 December 2002 - 05:25 AM Rate Topic: -----

#1 The Neoracle  Icon User is offline

  • Check, check, 1, 2.
  • member icon

Reputation: 21
  • View blog
  • Posts: 4,097
  • Joined: 30-March 01

Select all unique values. . .

Posted 02 December 2002 - 10:47 AM

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?
Is This A Good Question/Topic? 0
  • +

Replies To: Select all unique values. . .

#2 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: Select all unique values. . .

Posted 02 December 2002 - 09:19 PM

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...
Was This Post Helpful? 0
  • +
  • -

#3 arniie  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 999
  • Joined: 08-October 02

Re: Select all unique values. . .

Posted 03 December 2002 - 02:16 AM

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

but isn't GROUP BY exactly for this

ie

SELECT * FROM tablename GROUP BY fieldyouwantunique
Was This Post Helpful? 0
  • +
  • -

#4 MathewS  Icon User is offline

  • D.I.C Regular

Reputation: 18
  • View blog
  • Posts: 349
  • Joined: 14-May 02

Re: Select all unique values. . .

Posted 03 December 2002 - 03:20 AM

I think this is what you are looking for.

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


Was This Post Helpful? 0
  • +
  • -

#5 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: Select all unique values. . .

Posted 03 December 2002 - 08:31 AM

MathewS, on Dec 3 2002, 04:20 AM, said:

I think this is what you are looking for.

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


I knew there was an easier way, good going MatthewS
Was This Post Helpful? 0
  • +
  • -

#6 The Neoracle  Icon User is offline

  • Check, check, 1, 2.
  • member icon

Reputation: 21
  • View blog
  • Posts: 4,097
  • Joined: 30-March 01

Re: Select all unique values. . .

Posted 03 December 2002 - 10:51 AM

MathewS, on Dec 3 2002, 07:20 AM, said:

I think this is what you are looking for.

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


My Hero.
Was This Post Helpful? 0
  • +
  • -

#7 The Neoracle  Icon User is offline

  • Check, check, 1, 2.
  • member icon

Reputation: 21
  • View blog
  • Posts: 4,097
  • Joined: 30-March 01

Re: Select all unique values. . .

Posted 03 December 2002 - 03:34 PM

Unknown column 'DISTICT' in 'field list'
Was This Post Helpful? 0
  • +
  • -

#8 arniie  Icon User is offline

  • D.I.C Addict

Reputation: 0
  • View blog
  • Posts: 999
  • Joined: 08-October 02

Re: Select all unique values. . .

Posted 03 December 2002 - 03:50 PM

did you try my way?
Was This Post Helpful? 0
  • +
  • -

#9 The Neoracle  Icon User is offline

  • Check, check, 1, 2.
  • member icon

Reputation: 21
  • View blog
  • Posts: 4,097
  • Joined: 30-March 01

Re: Select all unique values. . .

Posted 03 December 2002 - 04:47 PM

arniie, on Dec 3 2002, 07:50 PM, said:

did you try my way?

That's just going to order them with all the same ones together, that's how they already are.
Was This Post Helpful? 0
  • +
  • -

#10 skrilla  Icon User is offline

  • boots.

Reputation: 2
  • View blog
  • Posts: 3,096
  • Joined: 05-July 02

Re: Select all unique values. . .

Posted 03 December 2002 - 07:38 PM

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

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


-pete
Was This Post Helpful? 0
  • +
  • -

#11 The Neoracle  Icon User is offline

  • Check, check, 1, 2.
  • member icon

Reputation: 21
  • View blog
  • Posts: 4,097
  • Joined: 30-March 01

Re: Select all unique values. . .

Posted 03 December 2002 - 08:44 PM

skrilla, on Dec 3 2002, 11:38 PM, said:

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

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


-pete

Fucking spelling.
Was This Post Helpful? 0
  • +
  • -

#12 Cookie Mobster  Icon User is offline

  • nooneenooneenooonee
  • member icon

Reputation: 7
  • View blog
  • Posts: 4,730
  • Joined: 12-October 01

Re: Select all unique values. . .

Posted 03 December 2002 - 08:48 PM

* Note: SELECT DISTINCT will not work properly with JOINED tables.
Was This Post Helpful? 0
  • +
  • -

#13 MathewS  Icon User is offline

  • D.I.C Regular

Reputation: 18
  • View blog
  • Posts: 349
  • Joined: 14-May 02

Re: Select all unique values. . .

Posted 04 December 2002 - 05:25 AM

opps, sorry about that.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1