SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2005
    0 Post(s)
    0 Thread(s)

    Question DISTINCT in combination with LIMIT


    I have one little question and try it in my best English.
    Can somebody help with this problem:

    I have built a Dutch puzzle dictionary and recently I built the 2nd version of it.
    There is a big change in the database structure, which is built as the following: (fieldnames are translated in English).

    id | description | synonym
    1 | color | blue
    2 | color | red
    3 | color | green
    4 | state of the USA | Oklahoma
    5 | state of the USA | Iowa
    6 | means of transport | car
    7 | means of transport | bicycle
    8 | color | white
    9 | state of the USA | Arkansas

    I have written a PHP-script which shows the results, where the synonyms of the same descriptions will be listened as following:

    color = blue, green, red, white
    means of transport = bicycle, car
    state of the USA = Arkansas, Iowa, Oklahoma

    Now I want to show only 5 results, so I have to LIMIT it with 5, but if I do so, I get the first 5 results. OK (you should say), but I want to use this way to show the first 5 results, but where the synonyms are the same (as in the example).

    Is there a way to LIMIT with DISTINCT?
    (I hope you understand what I exactly mean).

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2004
    0 Post(s)
    0 Thread(s)
    PHP Code:
    $x "color";
    $ret mysql_query("SELECT * FROM table 
                        WHERE description LIKE '
                        ORDER BY id LIMIT 5"
    $row mysql_fetch_array($ret)) {
    $y .= $row[2].",";
    $row[1]." = "substr($y0, -1);
    # echo's ie. color = blue, white, green, purple, red 


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts