读书人

多表查询不重复记录,该如何处理

发布时间: 2013-01-11 11:57:35 作者: rapoo

多表查询不重复记录


表menu
id int
parentNode varchar(50)
orderID int
表quanxian
userTypeName varcahr(50)
menuId int

SELECT DISTINCT[userTypeName]
,(menu.parentNode),menu.orderID
FROM [quanxian],menu
where quanxian.menuId=menu.id and [userTypeName]='管理员'
order by menu.orderID

想要查询menu.parentNode 不重复的记录,我写的不行,要是去掉menu.orderID的话就可以了,但是order by又必须在DISTINCT子语句里面,请问改怎么修改啊
[解决办法]
那就把name加上喽


SELECT menu.parentNode,userTypeName,min(menu.orderID) as orderID
FROM [quanxian],menu
where quanxian.menuId=menu.id and [userTypeName]='管理员'
group by menu.parentNode,userTypeName
order by orderID

读书人网 >SQL Server

热点推荐