Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Every derived table must have its own alias

Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Every derived table must have its own alias

문제쿼리
select *
from (
select rownum as rnum, tem.*
from (
select *
from board
<include refid=”search”/>
order by groups desc, step asc
) tem
)
where rnum between #{startRow} and #{endRow}

해결쿼리
select a.*
from (
select @rownum:=@rownum+1 as rnum, tem.*
from (
select *
from board
<include refid=”search”/>
order by groups desc, step asc
) tem, (select @rownum:=0) tnum
) a
where rnum between #{startRow} and #{endRow}

rownum은 oracle db에서 사용한다
mysql에서 rownum을 사용하는 방법
참고사이트 : http://cremazer.blogspot.kr/2013/09/mysql-rownum.html

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s