Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Join (SQL)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Cross join== <code>CROSS JOIN</code> returns the [[Cartesian product]] of rows from tables in the join. In other words, it will produce rows which combine each row from the first table with each row from the second table.<ref>[http://www.sqlguides.com/sql_cross_join.php SQL CROSS JOIN]</ref> {| class="wikitable" style="text-align:center" |- ! Employee.LastName !! Employee.DepartmentID !! Department.DepartmentName !! Department.DepartmentID |- | Rafferty || 31 || Sales || 31 |- | Jones || 33 || Sales || 31 |- | Heisenberg || 33 || Sales || 31 |- | Smith || 34 || Sales || 31 |- | Robinson || 34 || Sales || 31 |- | Williams || {{null result}} || Sales || 31 |- | Rafferty || 31 || Engineering || 33 |- | Jones || 33 || Engineering || 33 |- | Heisenberg || 33 || Engineering || 33 |- | Smith || 34 || Engineering || 33 |- | Robinson || 34 || Engineering || 33 |- | Williams || {{null result}} || Engineering || 33 |- | Rafferty || 31 || Clerical || 34 |- | Jones || 33 || Clerical || 34 |- | Heisenberg || 33 || Clerical || 34 |- | Smith || 34 || Clerical || 34 |- | Robinson || 34 || Clerical || 34 |- | Williams || {{null result}} || Clerical || 34 |- | Rafferty || 31 || Marketing || 35 |- | Jones || 33 || Marketing || 35 |- | Heisenberg || 33 || Marketing || 35 |- | Smith || 34 || Marketing || 35 |- | Robinson || 34 || Marketing || 35 |- | Williams || {{null result}} || Marketing || 35 |} Example of an explicit cross join: <syntaxhighlight lang=sql> SELECT * FROM employee CROSS JOIN department; </syntaxhighlight> Example of an implicit cross join: <syntaxhighlight lang=sql> SELECT * FROM employee, department; </syntaxhighlight>The cross join can be replaced with an inner join with an always-true condition:<syntaxhighlight lang="sql"> SELECT * FROM employee INNER JOIN department ON 1=1; </syntaxhighlight> <code>CROSS JOIN</code> does not itself apply any predicate to filter rows from the joined table. The results of a <code>CROSS JOIN</code> can be filtered using a <code>WHERE</code> clause, which may then produce the equivalent of an inner join. In the [[SQL:2011]] standard, cross joins are part of the optional F401, "Extended joined table", package. Normal uses are for checking the server's performance.{{Why|date=May 2021}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)