萬盛學電腦網

 萬盛學電腦網 >> 數據庫 >> mssql數據庫 >> Sql Server中通過父記錄查找出所有關聯的子記錄

Sql Server中通過父記錄查找出所有關聯的子記錄

可查4級Sql代碼

select menu_id,menu_name,Father_Id from Sys_Menu where menu_id='18' or Father_Id=18 or -- 一級、二級
Father_Id in (select menu_id from Sys_Menu a where  menu_id='18' or Father_Id=18) or   -- 三級
father_id in (select menu_id from sys_menu where Father_Id in (select menu_id from Sys_Menu a where  menu_id='18' or Father_Id=18)) -- 四級
copyright © 萬盛學電腦網 all rights reserved