Bird
0
0

Given two tables:

medium📝 query result Q4 of 15
PostgreSQL - Joins in PostgreSQL
Given two tables:
Colors:
id | color
1 | Red
2 | Blue

Shapes:
id | shape
1 | Circle
2 | Square
3 | Triangle

What will be the output of the query:
SELECT color, shape FROM Colors CROSS JOIN Shapes ORDER BY color, shape;?
A6 rows combining each color with each shape
B5 rows combining colors and shapes
C3 rows with matching ids only
D2 rows with colors only
Step-by-Step Solution
Solution:
  1. Step 1: Count rows in each table

    Colors has 2 rows, Shapes has 3 rows.
  2. Step 2: Calculate CROSS JOIN result

    Total rows = 2 * 3 = 6, each color paired with each shape.
  3. Final Answer:

    6 rows combining each color with each shape -> Option A
  4. Quick Check:

    Output rows = 2 colors * 3 shapes = 6 [OK]
Quick Trick: CROSS JOIN multiplies row counts for total output rows [OK]
Common Mistakes:
  • Assuming join filters rows by id
  • Counting only matching ids
  • Ignoring multiplication of rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes