How can ORDER BY and LIMIT be used in conjunction with fetchColumn() to retrieve specific rows from a database in PHP?

When using fetchColumn() to retrieve specific rows from a database in PHP, you can use the ORDER BY clause to sort the results and the LIMIT clause to limit the number of rows returned. By combining these two clauses with fetchColumn(), you can retrieve specific rows based on your sorting criteria and limit the number of results returned.

// Connect to the database
$pdo = new PDO('mysql:host=localhost;dbname=mydatabase', 'username', 'password');

// Prepare a SQL query with ORDER BY and LIMIT
$stmt = $pdo->prepare("SELECT column_name FROM table_name ORDER BY column_name LIMIT 10");

// Execute the query
$stmt->execute();

// Fetch the first column value from the first row
$column_value = $stmt->fetchColumn();