What is INNER JOIN in MySQL?

INNER JOIN in MySQL is a type of join that returns only the rows from two or more tables where there is a match based on a specified condition. This allows you to combine rows from multiple tables based on related columns, and it is commonly used to retrieve data that is spread across different tables.

Example of INNER JOIN

Here is an example of using INNER JOIN to combine data from two tables, `customers` and `orders`:

<?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "database_name"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $sql = "SELECT customers.name, orders.order_id FROM customers INNER JOIN orders ON customers.id = orders.customer_id"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "Name: " . $row["name"]. " - Order ID: " . $row["order_id"]. "<br>"; } } else { echo "0 results"; } $conn->close(); ?>

INNER JOIN MySQL JOIN SQL JOIN Data Retrieval Combined Data