CodeBlanks Logo Icon CodeBlanks

Comma JOIN

Learn the comma form of JOIN.

Comma JOIN

Writing tables separated by a comma is an implicit CROSS JOIN. Modern SQL prefers explicit CROSS JOIN.

SELECT c.name, p.name
FROM customers c, products p;

This query gives a cartesian product with old syntax.

c.name, p.name is selected from customers c, products p.

Comma JOIN — details

With a WHERE filter the comma form becomes an INNER JOIN. But readability is poor.

For example, FROM orders o, customers c WHERE o.customer_id = c.id is an older style; if you forget the WHERE it silently becomes a CROSS JOIN.

Practice Comma JOIN

Replace comma FROM with explicit CROSS JOIN.

Starter code

query.sql
-- explicit cross join
SELECT c.name, p.name
FROM customers c

Sample solution

query.sql
SELECT c.name, p.name
FROM customers c
CROSS JOIN products p;

Expected output

name   name
Ayşe   Kalem
Ayşe   Defter

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What is comma-separated FROM equivalent to?

  • INNER JOIN
  • LEFT JOIN
  • CROSS JOIN Correct answer
  • UNION

Explanation: Comma FROM is an implicit CROSS JOIN.

2 Replace comma with

Question
SELECT c.name, p.name
FROM customers c, products p
____;
Answer
SELECT c.name, p.name
FROM customers c, products p
CROSS JOIN;

Explanation: CROSS JOIN is the right answer.

3 Comma JOIN: match the terms

Term Meaning
comma implicit cross
CROSS JOIN explicit
WHERE filter
ON condition

All lessons in Intermediate