SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard triexa's Avatar
    Join Date
    Dec 2002
    Location
    Canada
    Posts
    2,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Selecting unique on multiple columns?

    So I have:
    - a publisher table (publisher_id)
    - a vendor table (vendor_id)
    - Items belonging to a vendor (item_id)

    I want to select (up to, if there is enough) a unique vendor id with a limit of 1 per publisher where the vendor table has a column (featured) set to 1...

    SELECT * FROM tblVendors
    WHERE featured = 1
    GROUP BY publisher_id, vendor_id

    Edit: Also, I DO want multiple vendor_ids who have a publisher_id of 0 or a non-matching publisher...

    That will still give me more than one of the same publisher_id if there are two different vendors under that publisher that are featured...

    Hope I made it clear enough... any ideas how I can accomplish this?
    AskItOnline.com - Need answers? Ask it online.
    Create powerful online surveys with ease in minutes!
    Sign up for your FREE account today!
    Follow us on Twitter

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,022
    Mentioned
    53 Post(s)
    Tagged
    2 Thread(s)
    no idea how your vendor and publisher tables are related

    if you want to select a unique vendor, why not just select it by passing in the value of vendor_id for the vendor you want?
    r937.com | rudy.ca | 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
  •