Garayed.com  

Go Back   Garayed.com > mySQL
FAQ Members List Calendar Search Today's Posts Mark Forums Read


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-07-2007, 12:57 PM
GarryJones
 
Posts: n/a
Default Distinct Syntax

I am having trouble with how to use "distinct"

I have a Table called "places" with the values "town" and "posnum"

The data can look like this

london, 333
london, 333
paris, 442
barcelona, 222
barcelona, 222
madrid, 222
madrid, 222
malaga, 988
malaga, 988
malaga, 988
malaga, 988
malaga, 988

I need to get a list of all the different towns and the value in
"posnum".

The value of "posnum" can apply to more than one town.

But a town can only have one value for "posnum"

What I need is to get the following list

london, 333
paris, 442
barcelona, 222
madrid, 222
malaga, 988

If I use

"SELECT DISTINCT town FROM places"

I get a distinct list of the five towns, but I can not see the
"posnum" field

What I would like to do is select * from places and ignore duplicate
towns.

This way I can obtain the name of each town once along with its
"posnum"

However, I can't work out the syntax to do this.

Any help greatfully appreciated.


Garry Jones
Sweden

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-07-2007, 01:11 PM
Dikkie Dik
 
Posts: n/a
Default Re: Distinct Syntax

> What I need is to get the following list
>
> london, 333
> paris, 442
> barcelona, 222
> madrid, 222
> malaga, 988
>
> If I use
>
> "SELECT DISTINCT town FROM places"
>
> I get a distinct list of the five towns, but I can not see the
> "posnum" field



that is because you did not ask for it.

SELECT DISTINCT town, posnum FROM places

would give you that: the entire list, but with duplicate rows removed.
If you want only one column to be distinct, read the manual about the
GROUP BY clause.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 07:20 AM.




LinkBacks Enabled by vBSEO 3.0.0 © 2007, Crawlability, Inc.