MYSQL - INNER JOIN Query

INNER JOIN keyword is used to join two tables and selects records that have matching values in both tables.

MYSQL Syntax :

SELECT field_name1, field_name2, ....
FROM table1
INNER JOIN table2
ON table1.field_name = table2.field_name;

 

Cross Join Query

MYSQL INNER JOIN – Venn Diagram

MYSQL Query Example :
SELECT * FROM tblstudent INNER JOIN tblresult on tblstudent.stud_id=tblresult.stud_id;

  • The INNER JOIN query selects all rows from both tables as long as there is a match between the columns.
  • You can use INNER JOIN in the SELECT, UPDATE and DELETE statements to join the MySQL tables.


Shell command script:
Also you can run INNER JOIN query using mysql command Prompt.
[root@host]# mysql -u root -p
Enter password:********

mysql> use aryatechno;
Database changed

mysql> SELECT stud_id, stud_name, marks_maths, marks_science FROM tblstudent INNER JOIN tblresult on tblstudent.stud_id=tblresult.stud_id;

 -------------------------------------------------------------------------------------
| stud_id   | Name             | Maths Marks | Science Marks |
--------------------------------------------------------------------------------------
|      1      | Manish Patel   |     55             |    65                  |   
|      2      | Jay Modi         |     78             |    69                  |   
|      3      | Hitesh Joshi    |     94             |    97                  |   
-------------------------------------------------------------------------------------

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

51218