A cross join performs a cartesian product on the tuples of the two sets.
SELECT * FROM Table1 CROSS JOIN Table2
Which circumstances render such an SQL operation particularly useful?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you have a ‘grid’ that you want to populate completely, like size and color information for a particular article of clothing:
Maybe you want a table that contains a row for every minute in the day, and you want to use it to verify that a procedure has executed each minute, so you might cross three tables:
Or you have a set of standard report specs that you want to apply to every month in the year:
The problem with maintaining these as views is that in most cases, you don’t want a complete product, particularly with respect to clothes. You can add
MINUSlogic to the query to remove certain combinations that you don’t carry, but you might find it easier to populate a table some other way and not use a Cartesian product.Also, you might end up trying the cross join on tables that have perhaps a few more rows than you thought, or perhaps your
WHEREclause was partially or completely missing. In that case, your DBA will notify you promptly of the omission. Usually he or she will not be happy.