当前位置: 代码迷 >> Sql Server >> 多表查询不重复记录,该如何处理
  详细解决方案

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

热度:62   发布时间:2016-04-24 23:54:59.0
多表查询不重复记录

表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