Click here to Skip to main content
Sign Up to vote bad
good
See more: SQL
USE [cms]
GO
/****** Object:  StoredProcedure [dbo].[SpGetRelatedProducts]    Script Date: 10/10/2012 23:55:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[SpGetRelatedProducts](@pid int)
AS
select *
from product join subcategory on subcategory.subcate_id=category.cate_id
where product.subcate_id in (
                              select subcate_id 
                              from product 
                              where pid = @pid
                            )
 
 

i want that all the products, which belong from different subcategory and these subcategories belongs from same category and also the columns of the subcategory table, thats why i used above join, but there is something wrong in the query.
Posted 10 Oct '12 - 9:21

Comments
Zoltán Zörgő - 10 Oct '12 - 15:36
Although I don't really got your intentions - I can not see, that you join the category table, but you use it in the join condition.
Rohit Shrivastava - 10 Oct '12 - 18:46
There should be a reference of category table? Do you have one. Please provide the tables and relationships. Is input parameter product id?
damodara naidu betha - 11 Oct '12 - 2:03
Can you post what is the result coming and what should be the desired out put along with input data?

1 solution

change
from product join subcategory on subcategory.subcate_id=category.cate_id
to
from product join subcategory on subcategory.subcate_id=product.subcate_id
and remove your where clause and replace it with:
where pid = @pid
  Permalink  
Comments
damodara naidu betha - 15 Oct '12 - 2:35
My 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 239
1 OriginalGriff 188
2 Mahesh Bailwal 149
3 Maciej Los 140
4 Tadit Dash 128
0 Sergey Alexandrovich Kryukov 10,214
1 OriginalGriff 7,819
2 CPallini 4,181
3 Rohan Leuva 3,522
4 Maciej Los 3,089


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 12 Oct 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid