SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select Distinct Sizes

    Hi all, I have a query which is selecting DISTINCT sizes from my database only it doesn't seem to be returning DISTINCT sizes. My query is below along with a screen grab of what the query is returning. Appreciate any help

    Code MySQL:
    SELECT DISTINCT sizes FROM products AS p LEFT JOIN 
    products_to_section as o ON p.id=o.prod_id WHERE o.section_name='all-accessories' 
    AND p.live='1'


  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,260
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    there are likely some extraneous spaces or other non-printable characters

    do a dump of those rows and show us the INSERT statements
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,260
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    by the way, you want to use INNER JOIN, not LEFT OUTER JOIN

    by using LEFT OUTER JOIN, you're saying that there might be rows in products_to_section that have a prod_id for a product that doesn't exist
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Evangelist
    Join Date
    Aug 2010
    Posts
    503
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey bud, you were absolutely correct, there was a few nasty spaces on the sizes, very annoying. Gone through them all now and removed any spaces and all is working perfectly. I'll be sure to use the PHP trim function next time to strip any spaces.

    Right ok, I'll take a look into using INNER JOIN. Thanks for the pointer


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
  •