How can SQL queries be optimized for better performance when retrieving data for PHP applications?

To optimize SQL queries for better performance when retrieving data for PHP applications, you can use techniques such as indexing columns frequently used in WHERE clauses, minimizing the number of columns retrieved, avoiding SELECT *, and using LIMIT when retrieving a large number of rows.

<?php
// Example of optimizing SQL query by indexing columns and using LIMIT
$query = "SELECT * FROM users WHERE status = 'active' ORDER BY created_at DESC LIMIT 10";
// Execute the query and fetch results
?>