Solved

how to change the query from oracle to  mysql.

Posted on 2016-10-05
3
57 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Creating and Managing Databases with phpMyAdmin in cPanel.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
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

920 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now