首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

关于一个sql的弱智有关问题

2012-04-14 
关于一个sql的弱智问题我现在需要写一个SQLSQL codeString hql from TbArticle model where 11 hql

关于一个sql的弱智问题
我现在需要写一个SQL  

SQL code
String hql = "from TbArticle model where 1=1 ";hql += "and model.subject.id = "+subjectId+" ";hql += "and model.type = 2 ";hql += "order by model.createTime desc";


持久化层用的是hibernate
数据库是oracle

问题 现在的hql语句能查出所有的,但是我想用hql语句只查第一条,怎么写 怎么写 求帮助!
我试了一下 加 limit 1 但是知道肯定不行 这个mysql的 求帮助 在线等 有答案就结贴

[解决办法]
SQL code
select * from(select * from TbArticle model order by model.createTime desc)where rownum<2
[解决办法]
不可以这样么?
SQL code
String hql = "select * from (select * from TbArticle model where 1=1 ";hql += "and model.subject.id = "+subjectId+" ";hql += "and model.type = 2 ";hql += "order by model.createTime desc)";hql += " where rownum<2";
[解决办法]
直接在 HQL 里面加where 判断不行么? 如果用sql查询,也可以,但是返回的是一个对象数组。

热点排行
Bad Request.