What SQL query can be used to select records from the last month in a database?

To select records from the last month in a database, you can use the following SQL query: ``` SELECT * FROM table_name WHERE date_column >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) ``` This query selects all records from the table where the date_column is greater than or equal to the current date minus one month. This will return all records that have a date within the last month. Complete PHP code snippet:

<?php
$servername = "your_servername";
$username = "your_username";
$password = "your_password";
$dbname = "your_dbname";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM table_name WHERE date_column >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  // output data of each row
  while($row = $result->fetch_assoc()) {
    echo "id: " . $row["id"]. " - Name: " . $row["name"]. "<br>";
  }
} else {
  echo "0 results";
}
$conn->close();
?>