1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Distinct one columnt, including the second column

Discussion in 'Databases' started by mahmood, Apr 8, 2006.

  1. #1
    I am trying to select 2 columns of a table, one of the distinct.

    At the moment I have this code working:
    SELECT DISTINCT `Town` FROM myTable
    PHP:
    Say it returns 10 result, now I want the ID columns with these results too.

    If I code:

    SELECT DISTINCT `Town`,`ID` FROM myTable
    PHP:
    It'll return far more result than I expect. I need only the same ten results but including ID.

    Any idea?
     
    mahmood, Apr 8, 2006 IP
  2. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    ditch the distinct, try using the group by clause.

    SELECT `Town`,`ID` FROM myTable GROUP by `Town`
     
    vectorgraphx, Apr 13, 2006 IP