MySQL Wildcards

MySQL Wildcards

MySQL Aliases

MySQL Aliases

MySQL Data Types

MySQL Data Types

MySQL Interview Questions

MySQL Interview Questions and Answers


MySQL INNER JOIN

In MySQL, INNER JOIN is used to fetch records from more than one table that have matching field or column values in both tables. It appears immediately after the FROM clause.

MySQL INNER JOIN Syntax

To fetch records from more than one tables that have matching field or column values in both tables, use the following syntax:

Syntax

SELECT col1, col2,....
FROM tablename1
INNER JOIN tablename2 ON tablename1.col1 = tablename2.col1;

Parameters:

tablename1 & tablename2: The table name from which you want to fetch records.

col1: The column or field name that will be return.

MySQL INNER JOIN example

The following MySQL, fetching "accountName" fields value from "tblbankdemataccountcharges" table and "banks" fields value from "tblbankheadquartersandaddress" table using INNER JOIN, both have matching column values in tables :

Example

SELECT A.accountName, B.banks 
FROM tblbankdemataccountcharges A 
INNER JOIN tblbankheadquartersandaddress B
ON A.bankId = B.pk LIMIT 6;

Note:

In the above example, we are fetching "accountName" fields value from "tblbankdemataccountcharges" table and "banks" fields value from "tblbankheadquartersandaddress" table, both have matching column values in tables.

You can use MySQL Command Line Client to fetch rows from multiple tables where the join condition is satisfied.. It will look like this: