SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    selecting distinct records using limit

    I have a situation where I want to present 10 records at a time for a like lookup but if there is a duplicate name, I only want to show it once and count as 1 in the 10 to be presented. To complicate it, the search is dependent on location so I can't consolidate the table prior to the selection.

    So if I use the example of Burger King and I do a search in a large city, there will be numerous records in that city but I just want to show one when the like lookup is 'Burg%' so i would like to see Burger King, Burger Shack, etc. even though there are 35 records in the query for Burger King in that city.

    Thanks

  2. #2
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Never mind, it seems to work fine with

    Code:
    SELECT name FROM t1 where city = 'boston' and name like 'Chi%'
    GROUP BY name limit 0,10

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    yes, that's a mysql enhancement to sql

    this --
    Code:
    GROUP BY name LIMIT 0,10
    is equivalent to this --
    Code:
    GROUP BY name 
    ORDER BY name LIMIT 0,10
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Evangelist
    Join Date
    Nov 2009
    Posts
    471
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting, I had actually gone back and added the ORDER BY so I will now remove that. I really appreciate the input.


Bookmarks

Posting Permissions

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