select count(*) from sys_menus where parentId=8;
select exists(select id from sys_menus where parentId=8);
只需要找到存在就行
两个基本上一样快
对parentid增加索引可以让后者更快一点点
也可以这样写, select 1 from sys_menus where parentId=8 limit 1;
需要找到存在还是推荐使用exists,exists会跟前语句进行比较,select exists(select id from sys_menus where parentId=8);
不如直接写成select id from sys_menus where parentId=8;