每行在sql联接查询中重复自身太多次 [英] each row repeating itself too many times in sql join query

查看:133
本文介绍了每行在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].[SpGetAllProducts](@cateid int)
AS
select *
from product 
inner join subcategory on subcategory.subcate_id = product.subcate_id
inner join category on subcategory.cate_id = @cateid





我希望所有产品都属于不同的子类别,这些子类别属于同一类别,也属于子类别表的列,但是在上面的代码中,这是一个问题,每行重复的次数太多...?





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, but in above code thr is a issue that each row repeating itself too many times...?

推荐答案

SELECT distinct *
  FROM product 
         INNER JOIN subcategory ON subcategory.subcate_id = product.subcate_id
         INNER JOIN category ON subcategory.cate_id = @cateid


这篇关于每行在sql联接查询中重复自身太多次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆