Syntax\n------\n\nROWNUM()\n\nDescription\n-----------\n\nROWNUM() returns the current number of accepted rows in the current context. It main purpose is to emulate the ROWNUM pseudo column in Oracle. For MariaDB native applications, we recommend the usage of LIMIT, as it is easier to use and gives more predictable results than the usage of ROWNUM().\n\nThe main difference between using LIMIT andROWNUM() to limit the rows in the result is thatLIMIT works on the result set while ROWNUM works on the number of accepted rows (before any ORDER orGROUP BY clauses).\n\nThe following queries will return the same results:\n\n``sql\nSELECT  FROM t1 LIMIT 10;\nSELECT  FROM t1 WHERE ROWNUM() <= 10;\n`\n\nWhile the following may return different results based on in which orders the rows are found:\n\n`sql\nSELECT  FROM t1 ORDER BY a LIMIT 10;\nSELECT  FROM t1 ORDER BY a WHERE ROWNUM() <= 10;\n`\n\nThe recommended way to use ROWNUM to limit the number of returned rows and get predictable results is to have the query in a subquery and test for ROWNUM() in the outer query:\n\n`sql\nSELECT  FROM (SELECT  FROM t1 ORDER BY a) WHERE ROWNUM() <= 10;\n`\n\nROWNUM() can be used in the following contexts:\n\n SELECT\n INSERT\n UPDATE\n DELETE\n* LOAD DATA INFILE\n\nUsed in other contexts, ROWNUM()` will return 0.\n\nExamples\n--------\n\nINSERT INTO t1 VALUES (1,ROWNUM()),(2,ROWNUM()),(3,ROWNUM());\n\nINSERT INTO t1 VALUES (1),(2) RETURNING a, ROWNUM();\n\nUPDATE t1 SET row_num_column=ROWNUM();\n\nDELETE FROM t1 WHERE a < 10 AND ROWNUM() < 2;\n\nLOAD DATA INFILE 'filename' INTO TABLE t1 fields terminated BY ',' \n  lines terminated BY "\\r\\n" (a,b) SET c=ROWNUM();\n\nURL: https://mariadb.com/docs/server/reference/sql-functions/secondary-functions/information-functions/rownum