inner join program code in PHP, MySQL
Inner join shows results from both tables where there is any match between columns in both tables.
In this example, the table t4tutorials_finance
is joining as the inner join with user_details
table.
The query of Inner Join
select * from t4tutorials_finance inner join user_details on user_details.userid=T4Tutorials_finance.t4tutorials_id
Inner Join Program Example in PHP, MYSQL
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<!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` inner 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> |
The database for the inner join program is shown below.
Video Lecture
Database t4tutorials_join for inner join
Download the database
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 |