SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Jun 2004
    Location
    UK
    Posts
    605
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Complicated SQL query

    Hi,

    I've got the following MS SQL tables:

    Code:
    tblProduct
    ----------
    Product_Id | Product_ManufacturerCode
    
    
    tblProductDetail
    ---------------
    ProductDetail_Id | ProductDetail_ManufacturerCode | ProductDetail_CategoryId
    
    
    tblCategory
    -----------
    Category_Id | Category_Name


    tblProductDetail is a huge table supplied by an external supplier. I only need the records where we have products in the tblProduct table.

    What I need to do is to select all distinct Category_Name values where tblProductDetail has a record in tblProduct.

    Does anyone know how to do this?

    Thanks very much...

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    697
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    select category_name
     from tbl_category
     where Category_Id in
       (select ProductDetail_CategoryId
          from tblProductDetail 
          join tblProduct on 
       tblProductDetail.ProductDetail_ManufacturerCode = tblProduct.Product_ManufacturerCode)


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
  •