MySQL INNER JOIN
MySQL INNER JOIN is used to combine two or more tables based on a matching condition. It returns only the rows where there is a match between the tables being joined. The syntax for INNER JOIN is as follows:
SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;
Here, table1 and table2 are the names of the tables being joined, and column_name is the name of the column used as the matching condition. The SELECT statement is used to specify the columns to be returned in the result set.
For example, let's say we have two tables - customers and orders. We want to retrieve the details of all customers who have placed an order. We can use INNER JOIN to achieve this as follows:
SELECT customers.customer_id, customers.customer_name, orders.order_date FROM customers INNER JOIN orders ON customers.customer_id = orders.customer_id;
In this example, we are joining the customers and orders tables on the customer_id column, which is present in both tables. We are also specifying the columns to be returned in the result set - customer_id, customer_name, and order_date. The result set will contain only the rows where there is a match between the two tables, i.e., customers who have placed an order
原文地址: https://www.cveoy.top/t/topic/gDJt 著作权归作者所有。请勿转载和采集!