Home > Database > Mysql Tutorial > 检索表上某一字段的不重复记录

检索表上某一字段的不重复记录

WBOY
Release: 2016-06-07 17:39:16
Original
1155 people have browsed it

select --要获取的目标字段列表 sys_menu.id, sys_menu.[order], sys_menu.parentid, sys_menu.[Name], sys_menu.url, sys_menu.icon, sys_menu.controllername, sys_menu.actionname, sys_menu.ismenu from priv_privilege --联合查询 left join sys_menu o

select

--要获取的目标字段列表
sys_menu.id,
sys_menu.[order],
sys_menu.parentid,
sys_menu.[Name],
sys_menu.url,
sys_menu.icon,
sys_menu.controllername,
sys_menu.actionname,
sys_menu.ismenu
from
priv_privilege

--联合查询
left join sys_menu on priv_privilege.privtypeid=sys_menu.id
where priv_privilege.id in
(

--关键在这里:通过这下面的语句将不重复的记录ID先select出来通过group by 语句
select
min(id)
from
priv_privilege
where
(privMaster='user' and privmasterid=1) or (privMaster='role' and privmasterid in(1,2,3))
group by
privtypeid
)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template