Explicit Cross Join in PHP

In this article I explain how to use explicit cross join in PHP
  • 2021


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

Explicitly Cross Join

To using the explicitly cross join, You write the cross join keywords after the first table name and before the second table name. Because of the way cross join works, you do not code ON clause that includes a Join condition.


SELECT select_list
FROM table1 CROSS JOIN  table2

Example of Explicit Cross Join in PHP



if (!$con)


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


mysql_select_db("mysql", $con);


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

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

echo "<table border='1'>






while($row = mysql_fetch_array($result))


   echo "<tr>";

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

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


  echo "</tr>";


  echo "</table>"; 





© 2020 DotNetHeaven. All rights reserved.