CEIL() in MySQL — How It Works
What the MySQL CEIL() function does, with an example.
Published October 21, 2026
CEIL(x) (alias CEILING) returns the smallest integer greater than or equal to x, rounding up.
How it works
Handy for pagination: pages = CEIL(total / per_page).
Try it in MySQL
SELECT CEIL(3.1)
4
SELECT CEIL(-3.9)
-3
SELECT CEIL(95 / 10)
10
Practical examples
Example 1
SELECT CEIL(3.1);
-- 4Example 2
SELECT CEIL(-3.9);
-- -3Example 3
SELECT CEIL(95 / 10);
-- 10Use it in a real query
SELECT id, CEIL(3.1) AS result
FROM your_table
LIMIT 10;Common mistakes
- Using it for currency rounding.
- Integer division before CEIL.
- Confusing with ROUND.
Key takeaways
- CEIL() in one line: CEIL(x) (alias CEILING) returns the smallest integer greater than or equal to x, rounding up.
- Try queries in a test database first.
- Check NULL handling and data types.
FAQ
Number of pages?
CEIL(COUNT(*) / page_size).
Does CEIL() work in other databases?
Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.