Solved

how to change the query from oracle to  mysql.

Posted on 2016-10-05
3
67 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
  • 2
3 Comments
 
LVL 33

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 33

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

828 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