Home » Joining Three Tables in mysql with examples

Joining Three Tables in mysql with examples

Joining Three Tables in mysql with examples

Joining Three or More Tables

Simple Although each join one query to specification joins only two tables and here example of the , FROM clauses can all the contain multiple join tables specifications. This allows many two or more tables to be joined tables for a single query.Joining Three Tables in mysql with examples

SELECT p.invoicename, v.invoicename
FROM Production.Product p
JOIN sallings.ProductVendor pv
ON p.ProductID = pv.ProductID
JOIN sallings.Vendor v
ON pv.bshopID = v.bshopID
WHERE psubID = 15
ORDER BY v.invoicename;

SQL join three tables or more tables based(INNER) on a parent-child relationship Examples

A SQL JOIN combines all the records from two tables or more tab. A JOIN locates tables related column all the values in the two or more tables. A query can contain only zero, one, or multiple level nested JOIN operations.here some example of INNER JOIN is the same as JOIN; like as a INNER Joining the keyword INNER is optional.

Read Also:  how to insert data from one database table to another database table in mysql?

SELECT s.productname
, s.product_id
, s.productdesc
, h.username
FROM products s
INNER JOIN users us
on s.product_id = us.product_id
INNER JOIN halls h
on us.userid = h.userid

How to join three or more tables in SQL query – MySQL Simple Example

Here is an simple example of SQL join three or more tables with conditions.

SELECT a.ord_num,u.cust_name,a.cust_code,  
p.agent_code,u.cust_city  
FROM products p,users u,orders a  
WHERE u.cust_city=p.working_area  
AND a.cust_code=u.cust_code  
AND a.agent_code=p.agent_code  

sql joining three tables using inner joins Example

A parent-child relationship Like (uniq id) between two tables can be created only one table mapped when there is a PRIMARY KEY in tables in one table and FOREIGN KEY other tables in another table.

Read Also:  What is the difference between Java and JavaScript?

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Inquiry Mst~~~~~~~~~~~~~~~~~~~~~~``*/

if(isset($page) && $page == "inquirymst")

{
  if(!empty($action) && $action == "ChangeStatus")
	{
		//print_r($_REQUEST);
		$inquiryid = $_REQUEST['id'];
		$status = $_REQUEST['status'];
		$rowid = $_REQUEST['rowid'];
		$tableName = $_REQUEST['tableName'];
		$changeStatus = '';
		if($status == 0){$changeStatus = '1';}
		else if($status == 1){$changeStatus = '0';}	
		$selUpdtData = "UPDATE  $tableName SET status = '$changeStatus' 
		WHERE inquiryid = '$inquiryid'" ;
		$selDistQtyQQ=mysql_query($selUpdtData) or die(mysql_error());
		//return status and page to redirect
		if($selDistQtyQQ)
		{
			$device_token = array();
			$deviceT = "SELECT u.devicetoken FROM inquirymst i
			left outer join usermst u on u.userid = i.userid
			WHERE trim(u.devicetoken) != ' ' AND i.inquiryid = '$inquiryid'";
			$deviceTQQ = mysql_query($deviceT);
			$deviceTCount = mysql_num_rows($deviceTQQ);
			if($deviceTCount > 0)
			{
				while($deviceTRR = mysql_fetch_array($deviceTQQ))
				{
					$device_token[] = $deviceTRR['devicetoken'];
				}				
			}
			$message = "Inquiry has been closed";
			$insertNotification = "INSERT INTO notification(userid,orderid,message,type,status,inquiryid)
			VALUES('$userid','$orderid','".addslashes($message)."','2','0','$inquiryid')";
			$insertNotificationQQ = mysql_query($insertNotification);
			if($deviceTCount > 0)
			{
				$res = functionSendNotifications($device_token,$message,'2',$inquiryid,'0');
			} 
			echo "success"."|".$rowid."|".$inquiryid."|".$changeStatus."|".'inquirymst';
		}
		else
		{
			echo "Error"."|".$rowid."|".$inquiryid."|".$staus."|".'inquirymst';
		}
	}
}

Join – Example

Read Also:  how to fetch data from database in codeigniter?

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Laravel Exception Handling Example Tutorial
  2. Read Also:  How to use Datatables in Laravel 5.8
  3. Read Also:  sql join multiple tables with conditions
  4. Read Also:  PHP utf8ize Encode with json_encode Example
  5. Read Also:  PHP cURL Download File From Url Example
  6. Read Also:  VueJS Call Function on Page Load Example
  7. Read Also:  PHP remove last element from an array
  8. Read Also:  Session Management Using Yii Framework
  9. Read Also:  VueJS Call Function on Page Load Example
  10. Read Also:  What is the difference between Java and JavaScript?

Leave a Comment

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