select distinct a.*
from Category a inner Join Info as b
on a.id=b.CategoryId
from Category a inner Join Info as b
on a.id=b.CategoryId
解决方案 »
- 牛人请进,触发器的问题
- sql server 2005如何回复DB.bak文件?
- 在SQL中统计一个字段 然后再插入到另一张表的一个字段
- 循环CREATE TABLE的表名问题。
- 询问关于查询排序问题
- 特殊编号问题,请教高手?
- 业务人员不小心用一个月以前备份的数据库文件还原了现正在使用的数据库,导致近一个月的数据丢失,请问有办法恢复吗?
- 复杂的SQL查询,高手请进来试一下!
- 为什么sql server会出现,“流水模式下,事务无法启动”????
- 请教-- MS sqlserver2000 + delphi问题?
- winXP P + Sql Server 2000个人版的问题
- 64位的sql 2000
(
select a.id,a.categorname,b.categoryid,b.infoname,b.id as id1 from Category a,info b
where a.id=b.categoryid
) a where
(select count(1) from
(
select a.id,a.categorname,b.categoryid,b.infoname,b.id as id1 from Category a,info b
where a.id=b.categoryid
) b where a.id=b.id and a.id1<b.id1)<1
from Category a
left outer join Info b on a.id=b.CategoryId
select info.ID,Category.CategoryName,info.InfoName
from Category,info
where info.CategoryId *=Category.Id
FROM Category a LEFT OUTER JOIN
Info b ON a.Id = b.CategoryId只是显示类别名称,如果只显示类别名称直接select * from Category就可以了
而我还要求显示其中一个产品名称,
多谢大家了!
insert @Category select 1,'AA' union select 2,'BB'declare @info table(Id int,CategoryId int,InfoName varchar(10))insert @info select 1,1,'a' union select 2,1,'b' union select 3,2,'aa' union select 4,2,'bb'
union select 5,2,'cc'select a.CategoryId,b.CategoryName,max(InfoName) from @info a,@Category b
where a.CategoryId = b.id group by CategoryId,b.CategoryName
/*CategoryId CategoryName
----------- ------------ ----------
1 AA b
2 BB cc
*/