How can the DISTINCT keyword be properly integrated into a SELECT statement in PHP?
When using the DISTINCT keyword in a SELECT statement in PHP, you need to include it immediately after the SELECT keyword to retrieve only unique rows from the result set. This can be useful when you want to eliminate duplicate rows from your query results. Make sure to include the DISTINCT keyword before specifying the columns you want to select.
$query = "SELECT DISTINCT column1, column2 FROM table_name";
$result = mysqli_query($connection, $query);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
// Process each row
}
}