Databases with SQLite

Cross Join

These type of joins should be used VERY carefully and judiciously - they are capable of producing HUGE amounts of output that may result in hair loss and skull cramps.

The result of any left join, inner join, or cross join
WITHOUT an ON or USING clause
is a cartesian product of all tables involved.

If you recall from school, a cartesian product is the quantity when the number of elements of EACH set are multiplied together.

So, if you have 2 tables with 14,338 and 27,800, elements in them, the resulting output will be 398,596,400 lines of output.

If that's what you really want then go for it. But you were warned.


There are cases when the task you need to perform requires a join of this type. If your tables are small enough, they are quite acceptable, but ALWAYS provide a condition. As an example we will use a smaller set of tables. The books table contains about 700 records and the authors table contains about 650 records.

select title,author from books cross join authors using (authorid) where pubyear=1985 order by title limit 10;
title                                       author
------------------------------------------  -------------------------------
Descent of Woman (The)                Morgan,Elaine
Horses and Other Animals in Motion    Muybridge,Edweard
Klutz Book of Knots (The)             Cassidy,John
Mathematical Gems III                 Honsberger,Ross
Mathematics for the Nonmathematician  Kline,Morris
Surely You're Joking, Mr. Feynman!    Feynman,Richard

Here we've joined 2 tables (books,authors) using the authorid as the linking element.
We've specified the publication year of interest, and also limited the output to 10.

A similar way to do the same thing with different syntax:

select title,author from books cross join authors on authors.authorid=books.authorid where pubyear=1985 order by title limit 10;
title                                 author
------------------------------------  -----------------
Descent of Woman (The)                Morgan,Elaine
Horses and Other Animals in Motion    Muybridge,Edweard
Klutz Book of Knots (The)             Cassidy,John
Mathematical Gems III                 Honsberger,Ross
Mathematics for the Nonmathematician  Kline,Morris
Surely You're Joking, Mr. Feynman!    Feynman,Richard

This illustrates precisely what the using (authorid) does in the previous example.

Note that in both cases, we did not have to specify the pubyear as part of the select statement, but were able to use it to filter our results.

Use which ever syntax makes sense to you - both give the same result.

Inner Join