Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. need help with inner join and oount sql server 2005

need help with inner join and oount sql server 2005

Scheduled Pinned Locked Moved Database
helpdatabasesql-serversysadminquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    VijayVishwakarma
    wrote on last edited by
    #1

    hi, I m trying to get values from three tables. 1) its has the sale id and product id 2) it has the product details based on id from 1st table, 3) it has the quantity of product being selected by the query. My problem is I need to check the count of the product based on various sizes and if its more than 0 i need to display available else sold out. I tried the following query. if I remove the count it works well to get the details but If I m gonna get the count it throws error. any suggestion where this query is wrong?? SELECT SaleProduct_tb.ProductId, Product_tb.BasePrice, Product_tb.SalePrice, Product_tb.PName, Product_tb.Image1, COUNT(ProductSizeQty.Quantity) AS Expr1 FROM SaleProduct_tb INNER JOIN Product_tb ON SaleProduct_tb.ProductId = Product_tb.ProductId INNER JOIN ProductSizeQty ON Product_tb.ProductId = ProductSizeQty.ProductId WHERE (SaleProduct_tb.SaleId = @SaleId) AND (SaleProduct_tb.CatId = @CatId) AND (SaleProduct_tb.SubCatId = @SubCatId) AND (Product_tb.BrandId = @BrandId) ORDER BY saleProduct_tb.ProductId

    Vijay V. Yash Softech

    A N 2 Replies Last reply
    0
    • V VijayVishwakarma

      hi, I m trying to get values from three tables. 1) its has the sale id and product id 2) it has the product details based on id from 1st table, 3) it has the quantity of product being selected by the query. My problem is I need to check the count of the product based on various sizes and if its more than 0 i need to display available else sold out. I tried the following query. if I remove the count it works well to get the details but If I m gonna get the count it throws error. any suggestion where this query is wrong?? SELECT SaleProduct_tb.ProductId, Product_tb.BasePrice, Product_tb.SalePrice, Product_tb.PName, Product_tb.Image1, COUNT(ProductSizeQty.Quantity) AS Expr1 FROM SaleProduct_tb INNER JOIN Product_tb ON SaleProduct_tb.ProductId = Product_tb.ProductId INNER JOIN ProductSizeQty ON Product_tb.ProductId = ProductSizeQty.ProductId WHERE (SaleProduct_tb.SaleId = @SaleId) AND (SaleProduct_tb.CatId = @CatId) AND (SaleProduct_tb.SubCatId = @SubCatId) AND (Product_tb.BrandId = @BrandId) ORDER BY saleProduct_tb.ProductId

      Vijay V. Yash Softech

      A Offline
      A Offline
      Ashfield
      wrote on last edited by
      #2

      Don't cross post, its rude.

      Bob Ashfield Consultants Ltd

      N V 2 Replies Last reply
      0
      • V VijayVishwakarma

        hi, I m trying to get values from three tables. 1) its has the sale id and product id 2) it has the product details based on id from 1st table, 3) it has the quantity of product being selected by the query. My problem is I need to check the count of the product based on various sizes and if its more than 0 i need to display available else sold out. I tried the following query. if I remove the count it works well to get the details but If I m gonna get the count it throws error. any suggestion where this query is wrong?? SELECT SaleProduct_tb.ProductId, Product_tb.BasePrice, Product_tb.SalePrice, Product_tb.PName, Product_tb.Image1, COUNT(ProductSizeQty.Quantity) AS Expr1 FROM SaleProduct_tb INNER JOIN Product_tb ON SaleProduct_tb.ProductId = Product_tb.ProductId INNER JOIN ProductSizeQty ON Product_tb.ProductId = ProductSizeQty.ProductId WHERE (SaleProduct_tb.SaleId = @SaleId) AND (SaleProduct_tb.CatId = @CatId) AND (SaleProduct_tb.SubCatId = @SubCatId) AND (Product_tb.BrandId = @BrandId) ORDER BY saleProduct_tb.ProductId

        Vijay V. Yash Softech

        N Offline
        N Offline
        NeverHeardOfMe
        wrote on last edited by
        #3

        add a GROUP BY clause (after the WHERE clause adn before the ORDER BY one) listing all the fields in the SELECT clause excpet the one you're COUNTing

        V 1 Reply Last reply
        0
        • A Ashfield

          Don't cross post, its rude.

          Bob Ashfield Consultants Ltd

          N Offline
          N Offline
          neilmajithia
          wrote on last edited by
          #4

          to be fair the guy was told to post here after posting in the asp.net forum.

          1 Reply Last reply
          0
          • N NeverHeardOfMe

            add a GROUP BY clause (after the WHERE clause adn before the ORDER BY one) listing all the fields in the SELECT clause excpet the one you're COUNTing

            V Offline
            V Offline
            VijayVishwakarma
            wrote on last edited by
            #5

            hi, thanks for the help.

            Vijay V. Yash Softech

            1 Reply Last reply
            0
            • A Ashfield

              Don't cross post, its rude.

              Bob Ashfield Consultants Ltd

              V Offline
              V Offline
              VijayVishwakarma
              wrote on last edited by
              #6

              someone suggested me to put that here. So I added here too. sorry for that.

              Vijay V. Yash Softech

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups