SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    Colorado Springs, CO
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Seperate Out Repeats on SQL Join

    Ok so I have my join working and am attempting to filter out any duplicates of a single column. I don't even know where to start for this. Basically on the join I want to check for any duplicates of the 'PropID' column and only post one copy of the PropID onto my webpage.

    What's the best method to accomplish this?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by kulmu View Post
    What's the best method to accomplish this?
    you might start by showing us your query, and sample results of what it currently produces as well as what you would like it to produce

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    Colorado Springs, CO
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    SELECT 
    a.PropID, a.PropName, a.LargeDogs, b.Size 
    FROM properties 
    AS a INNER JOIN 
    floorplans AS b 
    ON b.PropID = a.PropID 
    WHERE a.Active = '1' 
    AND b.Size LIKE '2BD%'
    ORDER BY a.PropID LIMIT 30
    I am getting duplicates from communities that have multiple floorplans on the same options. So Instead of showing PlanID 3 times when it loops I would like it to skip the duplicates and only display each PropID once, instead of 3 or 4 times as it can do now.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    gee, a different thread, but i'm sure i've seen that query before

    what would you like to show along with each unique PropID?

    obvioulsy if each property has multiple floorplans with sizes like '2BD%', then which size would you like to show?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    Colorado Springs, CO
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep just noticed it was you that replied. Other forum was the database one though and figured was best to move this over to the PHP forum.

    Basically just need the PropID to be unique.

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    so you don't need any sizes at all in the query results?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Location
    Colorado Springs, CO
    Posts
    31
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope just need to know they do exist. Basically there will be a page that has some checkboxes to select options that will be searched for. This query was hopefully going to accomplish that.

  8. #8
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    okay, do this:
    Code:
    SELECT DISTINCT
           a.PropID, a.PropName, a.LargeDogs
      FROM properties AS a 
    INNER 
      JOIN floorplans AS b 
        ON b.PropID = a.PropID 
     WHERE a.Active = '1' 
       AND b.Size LIKE '2BD%'
    ORDER 
        BY a.PropID LIMIT 30
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •