To merge records from two or more tables in a database, use the SQL Joins clause. A JOIN is a method of joining fields from two tables by using values that are shared by both.
CUSTOMERS TABLE (TABLE 1)
EMPLOYEE TABLE TABLE 2
Now, in our SELECT query, let's join these two tables as seen below.
mysql> select customers.cus_id, employee.name, employee.amount from employee
INNER JOIN customers ON employee.amount=customers.salary;
This would result in the following outcome:
It's worth noting that the join is done in the WHERE clause here. Tables can be joined using a variety of operators, including =, >,>, =, >=,!=, BETWEEN, LIKE, and NOT. The equal to symbol, on the other hand, is the most prevalent operator.
In SQL, there are a variety of joins to choose from.
|