Implicit Cross Join in PHP

In this article I explain how to use implicit cross join in PHP
  • 1773

Introduction

A  CROSS JOIN produce a result set in which each row from the first table is combined with each rows from the second table. Cross Join is also called Cartesian Product. Cross join have two types

  • Implicitly Cross Join
  • Explicitly Cross Join

Implicitly Cross Join

In implicit cross join you do not require to write the cross join keywords after the first table name and before the second table name, you can simple write select statement and pass table names and all names will be separate bycommas in from clause.

Syntax

SELECT select_list
FROM table1, table2

Example of Implicit Cross Join in PHP

<?php

$con=mysql_connect("localhost","root","");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

mysql_select_db("mysql", $con);

 

print "<h2>MySQL: Cross Join Implicitly</h2>";

$result = mysql_query("select fname,role from emp, designation ");

echo "<table border='1'>

<tr>

<th>Role</th>

<th>Firstname</th>

 

</tr>";

while($row = mysql_fetch_array($result))

  {

   echo "<tr>";

   echo "<td>" . $row['role'] . "</td>";

   echo "<td>" . $row['fname'] . "</td>";

 

  echo "</tr>";

  }

  echo "</table>"; 

 mysql_close($con);

  ?>

 Output

mysql-implicit-cross-join-in-php.jpg

© 2019 DotNetHeaven. All rights reserved.