Right join shows all rows from the Right table and shows only matching rows from the left table.
In this example,t4tutorials_finance is the left table and user_details is the right table.
What will be displayed?
Left join shows all rows from the left table user_detailsand shows only matching rows from the right table t4tutorials_finance .
Left join Query in MySQLi
select * from t4tutorials_finance right join user_details on user_details.userid=T4Tutorials_finance.t4tutorials_id
<!DOCTYPE html>
<html>
<head>
<title>Left Join Tables using Left Join PHP and MySQLi</title>
</head>
<body>
<table border="1">
<thead>
<th>Salary</th>
<th>Firstname</th>
<th>Lastname</th>
</thead>
<tbody>
<?php
$conn = mysqli_connect("localhost","root","","t4tutorials_Join");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query=mysqli_query($conn,"select * from `t4tutorials_finance` right join user_details on user_details.userid=T4Tutorials_finance.t4tutorials_id");
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $row['t4tutorials_salary']; ?></td>
<td><?php echo $row['firstname']; ?></td>
<td><?php echo $row['lastname']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
</body>
</html>
Output
| Salary | Firstname | Lastname |
| 80000 | fazal | rehman |
| shamil | khan | |
| sharjeel | bhutta |
Right Join Program Example in PHP, MySQLi
The database for the code is shown below in the figure.
Video Lecture
Database t4tutorials_join
Download the database for right join
Table structure for table t4tutorials_finance
| Column | Type | Null | Default |
| t4tutorials_id | int(222) | No | |
| t4tutorials_salary | int(222) | No |
Table structure for table user_details
| Column | Type | Null | Default |
| userid | int(11) | No | |
| firstname | varchar(30) | No | |
| lastname | varchar(30) | No |


