Display two table data in a single table using sql inner join query | Sanwebcorner

Display two table data in a single table using sql inner join query

In this post i am explain about to display the two mysql table data in single table using mysql inner join query . The two tables are personalinfo, salaryinfo in that two tables i am using common id is called as a empid using this i am selected two different table datas  in single view.

 I am displaying the data name, contactnumber from personallinfo table and then esi, pf, salary from salaryinfo table and then i am displaying in a single table using empid as a common id.

display the table using inner join query

Create Database:

create database emp;

Create Table: personalinfo
CREATE TABLE  `emp`.`personalinfo` (
`empid` int(6) not null,
`name` VARCHAR( 150 ) NOT NULL ,
`contactnumber` INT( 200 ) NOT NULL ,
`mail` VARCHAR( 200 ) NOT NULL

Create Table: salaryinfo

CREATE TABLE `emp`.`salaryinfo` (
`empid` int(6) not null,
`salary` varchar(5) not null,
`esi` varchar(4) not null,
`pf` varchar(4) not null


<title>Display more then one table data in single table using joinquery</title>
<body bgcolor="#85B80E">
// Check connection
if (mysqli_connect_errno())
  echo "Failed to connect to MySQL: " . mysqli_connect_error();

$result = mysqli_query($con,"SELECT personalinfo.name, personalinfo.contactnumber, salaryinfo.esi, salaryinfo.pf, salaryinfo.salary FROM personalinfo INNER JOIN salaryinfo ON personalinfo.empid=salaryinfo.empid");
echo " <center><h1>JOIN QUERY </h1></center>";
echo "<table border='1' align='center' cellpadding='15' bgcolor='#FFFFFF'>

while($row = mysqli_fetch_array($result))
  echo "<tr>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['contactnumber'] . "</td>";
  echo "<td>" . $row['esi'] . "</td>";
  echo "<td>" . $row['pf'] . "</td>";
  echo "<td>" . $row['salary'] . "</td>";
  echo "</tr>";
echo "</table>";

<table bgcolor="#FFFFFF"

Download Code

Post a comment


360 degree view product image 3d rotate 3d text 3step-form Accordion menu ajax All Browsers Animated Background Gradient animation audio controller auto complete Best accordion menu bootstrap Bootstrap form validation border bounce effect on hover Breadcrumb calculate age by dob calendar Captcha change image on mouse move color chooser countdown Counter on scroll create random number Css css animation css buttons css hover css3 customized upload Button Date picker delete data from table Different scroll speed donation form download zip email otp verification email verifier Embed eventlist Expanding Menu feedbck form flash news section close button full screen menu Google custom search Google Maps Google reCAPTCHA Google site search gradient heart animation hide menu Horizontal News ticker Hover Htm Html html dropdown html form html form validation html5 html5 form validation Iframe image hover increment decrement textbox value based on select box Javascript javascript validation Jquery jquery validation js Layered image effect on mouse hover lock & unlock page scroll marquee marquee with close button mobile number validation mobile otp login Multi-level-drop-down-menu multi-level-form multi-select-checkbox Multi-Step-form Multiple File Upload in PHP mysql News ticker on hover change text to image our team page password generator password strength checker paypal form paypal html form Photoshop PHP php mailer populate html selectbox Popup image on click the link pure css Question type form random number generate Random password Redirect page Based on the select box while submit the form responsive responsive menu responsive popup box Responsive Vertical Time line design rotate image selectbox based on select box simple coming soon page simple countdown based on end date simple typing effect slider sliding tab sms otp login statistic counter on scroll switch tag shape team member Time picker toggle toggle view transparent button underline animation up down slide validation vertical fixed sidebar Webtips whatsapp link website Whislist Youtube