SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard
    Join Date
    Nov 2000
    Location
    Chico, Ca
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting multipules of the Same Item

    I'm not sure whats going on:

    SQL:

    Code:
     Select Distinct Products.ProductID, Products.Name, Products.Description, Products.ImageName, Products.Price, Categories.CategoryID, Categories.Name From Products, Categories, Category_Product 
      where Products.ProductID = Category_Product.ProductID and  Category_Product.CategoryID = 4


    Results:

    Code:
    11	Shredded Barks: Walk-on Bark and Shredded Cedar	Decorative mulch used in planter beds to retain soil moisture and inhibit week germination. Stays in place on slopes better than other barks. 221204031002	24	4 Bark
     11	Shredded Barks: Walk-on Bark and Shredded Cedar	Decorative mulch used in planter beds to retain soil moisture and inhibit week germination. Stays in place on slopes better than other barks. 221204031002	24	5 Rocks
     11	Shredded Barks: Walk-on Bark and Shredded Cedar	Decorative mulch used in planter beds to retain soil moisture and inhibit week germination. Stays in place on slopes better than other barks. 221204031002	24	6 Soil
     11	Shredded Barks: Walk-on Bark and Shredded Cedar	Decorative mulch used in planter beds to retain soil moisture and inhibit week germination. Stays in place on slopes better than other barks. 221204031002	24	7 Pavers
     11	Shredded Barks: Walk-on Bark and Shredded Cedar	Decorative mulch used in planter beds to retain soil moisture and inhibit week germination. Stays in place on slopes better than other barks. 221204031002	24	8 Miscellaneous
     13	Pebble/Chip Bark	Small Bark  1 average size Medium Bark  2-3 average size Mini-Bark   average size	Decorative mulch used in planter beds to retain soil moisture and inhibit weed germination. 	221204031231	24 4	Bark
     13	Pebble/Chip Bark	Small Bark  1 average size Medium Bark  2-3 average size Mini-Bark   average size	Decorative mulch used in planter beds to retain soil moisture and inhibit weed germination. 	221204031231	24 5	Rocks
     13	Pebble/Chip Bark	Small Bark  1 average size Medium Bark  2-3 average size Mini-Bark   average size	Decorative mulch used in planter beds to retain soil moisture and inhibit weed germination. 	221204031231	24 6	Soil
     13	Pebble/Chip Bark	Small Bark  1 average size Medium Bark  2-3 average size Mini-Bark   average size	Decorative mulch used in planter beds to retain soil moisture and inhibit weed germination. 	221204031231	24 7	Pavers
     13	Pebble/Chip Bark	Small Bark  1 average size Medium Bark  2-3 average size Mini-Bark   average size	Decorative mulch used in planter beds to retain soil moisture and inhibit weed germination. 	221204031231	24 8	Miscellaneous
     14	Playground Bark	A cedar wood chip primarily used for cushioning under playground equipment. Government-approved as an under-layment.	 221204031642	24	4 Bark
     14	Playground Bark	A cedar wood chip primarily used for cushioning under playground equipment. Government-approved as an under-layment.	 221204031642	24	5 Rocks
     14	Playground Bark	A cedar wood chip primarily used for cushioning under playground equipment. Government-approved as an under-layment.	 221204031642	24	6 Soil
     14	Playground Bark	A cedar wood chip primarily used for cushioning under playground equipment. Government-approved as an under-layment.	 221204031642	24	7 Pavers
     14	Playground Bark	A cedar wood chip primarily used for cushioning under playground equipment. Government-approved as an under-layment.	 221204031642	24	8 Miscellaneous
    I'm trying to get one instance of each product back.
    "Happiness doesn't find you, you find happiness" -- Unknown
    www.chuckknows.com

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,220
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    you forgot the join condition between Category_Product and Categories
    Code:
    select Categories.Name 
         , Products.ProductID
         , Products.Name
         , Products.Description
         , Products.ImageName
         , Products.Price
      from Categories
    inner
      join Category_Product  
        on Categories.CategoryID
         = Category_Product.CategoryID
    inner
      join Products
        on Category_Product.ProductID
         = Products.ProductID 
     where Category_Product.CategoryID = 4
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2000
    Location
    Chico, Ca
    Posts
    1,125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! It's been a little while since I wrote much SQL. I think joins are the first to go when I don't use SQL.

    Thanks again,

    Chuck
    "Happiness doesn't find you, you find happiness" -- Unknown
    www.chuckknows.com


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
  •