- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
Empowering Insights, Unleashing Possibilities
Data Science/Business Analytics for Small Business Applications › Forums › SQL › Counting number of records after applying Cartesian JOIN
Tagged: Cartesian join SQL
Here is the problem:
All of the questions in this quiz pull from the open source Chinook Database. Please refer to the ER Diagram below and familiarize yourself with the table and column names to write accurate queries and get the appropriate answers.
How many records are created when you apply a Cartesian join to the invoice and invoice items table?
Here is my tentative solution:
SELECT * FROM invoices JOIN invoice_items ON invoices.invoiceid = invoice_items.invoiceid
The solution that I am getting of 2240 records incorrect (Output limit exceeded, 25 of 2240 total rows shown).
Seeking help where I am going wrong.
Reply
Cartesian join == CROSS JOIN
https://www.sqlitetutorial.net/sqlite-cross-join/
The question is perhaps what happens when you apply a Cartesian JOIN to the two tables (no filtering with a WHERE clause). Your original query filters the results, so you’re not getting a proper count of rows.
Combine CROSS JOIN with COUNT.
SELECT COUNT(*) FROM invoices CROSS JOIN invoice_items
In SQLite JOIN without an ON clause is effectively the same as a CROSS JOIN.