四联表的级联查询(嵌套)

Posted 普通网友

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了四联表的级联查询(嵌套)相关的知识,希望对你有一定的参考价值。

	@RequestMapping(value = "/list")
	public String list(Model model, HttpServletRequest request, String flag,
			String ghsId, String xsId, String ypId, String yyId)
			throws Exception 
		String sql = "select a.*,(select name from t_ghs b where a.ghsId=b.id) name ,(select name from t_xs b where a.xsId=b.id) man ,(select name from t_yp b where a.ypId=b.id) hao ,(select name from t_yy b where a.yyId=b.id) ni  from t_flow a where 1=1";

		if (ghsId != null && !"".equals(ghsId)) 
			sql += " and ghsId ="+ghsId;
		
		if (xsId != null && !"".equals(xsId)) 
			sql += " and xsId ="+xsId;
		
		if (ypId != null && !"".equals(ypId)) 
			sql += " and ypId ="+ypId;
		
		if (yyId != null && !"".equals(yyId)) 
			sql += " and yyId ="+yyId;
		
		sql += " order by id desc";
		List list = db.queryForList(sql);
		request.setAttribute("list", list);
		return "/admin/flow/list";
	
	

四联表的级联查询

    String sql = "select a.*,(select name from t_ghs b where a.ghsId=b.id) name ,(select name from t_xs b where a.xsId=b.id) man ,(select name from t_yp b where a.ypId=b.id) hao ,(select name from t_yy b where a.yyId=b.id) ni  from t_flow a where 1=1";

以上是关于四联表的级联查询(嵌套)的主要内容,如果未能解决你的问题,请参考以下文章

如何更新链接到多个表的 FK - 更新时的级联

SqlServer触发器实现表的级联插入级联更新

关于数据的级联删除和更新

如何实现关系表的级联删除(ON DELETE CASCADE的用法)

student表中创建触发器,实现student表和student _course表的级联删除

mybatis怎么有条件的级联查询????