Questions tagged [cross-join]

CROSS JOIN is a join operation, that returns the Cartesian product of rows from tables in the join. In other words, it will produce rows which combine each row from the first table with each row from the second table. Unlike other JOIN operators, it does not let you specify a join clause. You may, however, specify a WHERE clause in the SELECT statement.

CROSS JOIN is a JOIN operation that produces the Cartesian product of two tables. Unlike other JOIN operators, it does not let you specify a join clause. You may, however, specify a WHERE clause in the SELECT statement.

Examples

The following SELECT statements are equivalent:

SELECT *
FROM TEACHER
CROSS JOIN COURSE

SELECT *
FROM TEACHER, COURSE;

The following SELECT statements are equivalent:

SELECT *
FROM TEACHER
CROSS JOIN COURSE
WHERE TEACHER.ID = COURSE.TEACHER_ID

SELECT *
FROM TEACHER
INNER JOIN COURSE
ON TEACHER.ID = COURSE.TEACHER_ID

A CROSS JOIN operation can be replaced with an INNER JOIN where the join clause always evaluates to true (for example, 1=1). It can also be replaced with a sub-query. So equivalent queries would be:

SELECT * FROM TEACHER LEFT OUTER JOIN
COURSE INNER JOIN UNIVERSITY ON 1=1
ON TEACHER.ID = UNIVERSITIES.TEACHER_ID
WHERE UNIVERSITY.COUNTRY = 'US'

SELECT FROM TEACHER LEFT OUTER JOIN
(SELECT FROM COURSE, UNIVERSITY) S
ON TEACHER.ID = S.TEACHER_ID
WHERE S.COUNTRY = 'US'

Links

Cross Join in Oracle

530 questions
-2
votes
1 answer

How can I Compare two tables without relationship (1 table with 40k records and the other one with 7k records)?

I tried using Cross Join but it takes 5 minutes to run, there is another way to do that? Note: I'm comparing dates and Int Fields, Table 1 has records from a system and table 2 store a work calendar dates. SQL Server. B FILE C FILE Trying to…
JC_BI
  • 419
  • 1
  • 5
  • 16
-2
votes
1 answer

How to use inner join and cross join in one query?

I have a task to write a query that uses a single inner join and cross join(s). The query I have already written that should return the same result looks like this : SELECT T.PRICE, S.ROW, S.NUMBER, M.TITLE FROM [cinema_no_keys].[dbo].[TICKET] T…
Patryk
  • 22,602
  • 44
  • 128
  • 244
-3
votes
0 answers

SQL CASE WHEN CROSS JOIN

I am trying to do a calculation based on a lookup table doing a cross join and I am trying to select just 1 record per ID. This is on a SQL Server 2019 server. I want 1 record from the TechFee table and the TechFee from the TechFeeTiers table where…
tjestesjr
  • 53
  • 5
-4
votes
4 answers

Is CROSS JOIN all we need?

If we got rid of INNER JOIN, LEFT JOIN. RIGHT JOIN, and FULL JOIN tomorrow, could we completely replace their functionality with CROSS JOIN and filters on it? I initially thought that we obviously could, but edge cases such as this one have given me…
J. Mini
  • 1,868
  • 1
  • 9
  • 38
1 2 3
35
36