MySQL

adplus-dvertising
Inner Join in MySQL
Previous Home Next

It is almost similar to join query syntax and gives the similar output as join gives, just replace JOIN as INNER JOIN.

Syntax for inner join

SELECT columnname1, columnname2
FROM tablename1
INNER JOIN tablename2 ON common condition1
INNER JOIN tablename3 ON common condition2

Example

SELECT *
FROM studadr 
INNER JOIN studinfo 
ON studinfo.sid = studadr.sid ;

The table define after from clause is the first output followed by second table output in single output, here we have define 'studadr' followed by 'studinfo'.

Example

SELECT *
FROM studinfo 
INNER JOIN studadr 
ON studinfo.sid = studadr.sid ;

The above code gives the reverse result as the table order define in the clause.

Example

SELECT fname,age,lname,street
FROM studinfo
INNER JOIN studadr 
ON studinfo.sid = studadr.sid ;

In the above code we can reverse the table name order but the result will remain same, we can change the output order like street , age n anything to get the desired order result.

Example

SELECT fname,age,lname,street
FROM studinfo
INNER JOIN studadr 
ON studinfo.sid = studadr.sid 
WHERE studinfo.sid > 105
order by fname ;

In the above code we have can use either WHERE clause or ORDER BY clause , but here can use both to get the desired output on the specified condition.

Example

SELECT *
FROM studadr
INNER JOIN studinfo ON studinfo.sid = studadr.sid
Inner join studptin ON studadr.said=studptin.said ;

Output:

This gives the combination of all the three tables define in the above code, to get the shorter and select result check the next code.

Example

SELECT Name, Fname, Street
FROM studadr
INNER JOIN studinfo ON studinfo.sid = studadr.sid
Inner join studptin ON studadr.said = studptin.said;

In the above code we get the selected output like Name from STUDPTIN Table , Fname From STUDINFO Table and street From STUDADR Table and the comman table that contain the join of both the table is STUDADR is use in from condition.

Previous Home Next