原生sql 多表查询

   Session session =Session session = super.getSession();
   session.flush();
   Connection con = session.connection(); 

     String uid="";
     StringBuffer sql = new StringBuffer();
        sql.append("select a.user_Id from user_info as a");//user用户表
     sql.append( left join  (select b.userid from B_info as b where b.userid="+uid+"  
      and ( b.bdate=     (select max(bdate) from b_info where  userid=b.userid)) )) as binfo on a.user_id=binfo.userid

      Statement stmt = (Statement) con.createStatement();
      ResultSet rs = stmt.executeQuery(sql.toString());
     while(rs.next())  
        {  
      uid=rs.getString(1);
        
     }

     return uid;
 }

 

 

你可能感兴趣的:(sql)