Solved

how to change the query from oracle to  mysql.

Posted on 2016-10-05
3
80 Views
Last Modified: 2016-10-06
below query has been written in oracle.how to change this query in mysql.

select *
               from (
                    select rownum as rn, a.*
                    from (select * from test
                            where test_datetime  <= #{testDate}
                          order by test_datetime asc) a
                          )
              where rownum <= #{pageSize} and rn > #{offset}
0
Comment
Question by:chaitu chaitu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 34

Expert Comment

by:ste5an
ID: 41829830
It's exactly the same in MySQL.

The interesting part is: In what front-end do you use? Cause the parameter format looks pretty suspicious.
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 41829842
java.
Is rownum  there in mysql?
0
 
LVL 34

Accepted Solution

by:
ste5an earned 500 total points
ID: 41829858
Ah, I see. In this case you need an iterator:

SELECT T.*, 
       @rownum := @rownum + 1 AS rownum
  FROM yourTable T, 
       (SELECT @rownum := 0) R

Open in new window


E.g. untested
SELECT  * ,
		@rownum := @rownum + 1 AS rownumO
FROM    ( SELECT	@rownum := @rownum + 1 AS rownumI ,
                    A.*
          FROM      ( SELECT    *
                      FROM      test
                      WHERE     test_datetime <= '#{testDate}'
                      ORDER BY  test_datetime ASC
                    ) A,
					 (SELECT @rownum := 0) RI
        ) B ,
		(SELECT @rownum := 0) RO
WHERE   rownumI <= '#{pageSize}'
        AND rownumO > '#{offset} '

Open in new window

0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Via a live example, show how to take different types of Oracle backups using RMAN.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question