user1391800
user1391800

Reputation:

DB2 9 Fundamentals

Given the following two tables:

NAMES

NAME          NUMBER
----------    -------
Wayne Gretzky 99
Jaromir Jagr  68
Bobby Orr      4
Bobby Hull    23
Mario Lemieux 66

POINTS
-----------------------------
NAME           POINTS
----------     ------
Wayne Gretzky  244
Bobby Orr      129
Brett Hull     121
Mario Lemieux  189
Joe Sakic       94

How many rows would be returned using the following statement? SELECT name FROM names, points

Can someone explain why the answer is 25? Thanks in advance for any help provided

Upvotes: 0

Views: 51

Answers (2)

Josh Hull
Josh Hull

Reputation: 1783

Also known as the "Cartesian Product"

"The Cartesian product, also referred to as a cross-join, returns all the rows in all the tables listed in the query. Each row in the first table is paired with all the rows in the second table. This happens when there is no relationship defined between the two tables."

from:

http://www.dba-oracle.com/t_garmany_9_sql_cross_join.htm

Upvotes: 0

Philippe Grondier
Philippe Grondier

Reputation: 11138

I guess this instruction is equivalent to a cross join in standard SQL. Hence the number of records returned is 5 records in names * 5 records in points = 25.

Upvotes: 1

Related Questions