Explicit Cross Join in PHP
In this article I explain how to use explicit cross join in PHP
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
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.
Syntax
SELECT select_list
FROM table1 CROSS JOIN table2 |
Example of Explicit 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 Explicitly</h2>";
$result = mysql_query("select fname,role from emp CROSS JOIN designation ");
echo "<table border='1'>
<tr>
<th>Role</th>
<th>Firstname</th>
</tr>";<br>
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
