Code snippets
Code snippets
Copy-ready answers to everyday coding questions, each with a short explanation. Laravel, PHP, JavaScript, SQL, Bash and more.
2 snippets tagged #limit · Show all
SQL
October 20, 2026
MySQL get the Nth highest salary using LIMIT OFFSET
A classic interview question. DISTINCT skips ties, and OFFSET N-1 jumps to the Nth value. This example returns the 2nd highest.
SELECT DISTINCT salary
FROM employees
ORDER BY salary DESC
LIMIT 1 OFFSET 1; -- change the offset for the 3rd, 4th, etc.
PHP
October 19, 2026
Laravel rate limit API routes with throttle middleware
Limits how many requests a client can make per minute and returns a 429 when exceeded. Use it on login, API and public endpoints to stop abuse.
<?php
// routes/api.php: 60 requests per minute
Route::middleware('throttle:60,1')->group(function () {