Oracle-like ROWNUM in MySQL
It needs sometimes to exactly mimic Oracle's ROWNUM where is no possibility to initiate a counter in previous statement by SET @rownum:=0;.
It is still possible in a single SQL.
SELECT @rownum:=@rownum+1 rownum, t.*FROM (SELECT @rownum:=0) r, mytable t;
It is still possible in a single SQL.
SELECT @rownum:=@rownum+1 rownum, t.*FROM (SELECT @rownum:=0) r, mytable t;

11 Comments:
Thanks, useful for me.
does not work with a view...
really useful.....
thanks a lot!
nice very help full
Thank you very much! Very useful.
Top stuff.....thanks
you can get Wow Power Leveling and wow gold wow power leveling
Nice tip. How can we use this in update query
UPDATE test t
SET CREATED_BY=301 , CREATION_DATE=NOW()
WHERE
AND DOMAIN_ID=0
AND REJECT_COUNT=0
ORDER BY Q_CREATION_DATE
--@rownum<10; want to limit the result set which is ordered by date.
Just use LIMIT:
UPDATE test t
SET CREATED_BY=301 , CREATION_DATE=NOW()
WHERE
AND DOMAIN_ID=0
AND REJECT_COUNT=0
ORDER BY Q_CREATION_DATE
LIMIT 10
you have a nice site. thanks for sharing this valuable resources. keep it up. anyway, various kinds of ebooks are available here
http://feboook.blogspot.com
Post a Comment
<< Home