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
-1
votes
2 answers

BigQuery left join seems to be doing a cross join instead

I have two tables in BigQuery - one which contains ppc advertising data, another containing enquiries. I'd like to join the two so I can report ppc revenue vs spend per day. This initially felt pretty simple, but I've tried both a simple left join…
Adam Hopkinson
  • 28,281
  • 7
  • 65
  • 99
-1
votes
2 answers

Cross Join on two different tables in Spotfire

I have two data tables in Spotfire and the data source of these datatables is CSV. I want to add columns from one datatable to another based on Cross Join. If the datatables source is Information Link I would have modified the sql in the Information…
-1
votes
1 answer

How to join two tables with date and week number?

How do i connect both these tables to have data connected based on department names and week number. So that if the weeknumber don't match up, it shows nulls for others. http://sqlfiddle.com/#!6/3bbd3/1
Manny Balboa
  • 73
  • 2
  • 4
  • 15
-1
votes
3 answers

naural join is giving Cartesian product of two relations

I have two relations, emp(id,name) and emp2(name,city,salary) with values: and relation emp2 values : As you can see, when I run natural join between them I get their Cartesian product. But why, since they have a common attribute (name)?
-1
votes
1 answer

Relational Algebra Cross Join (Cross Product) and Natural Join

When do I use operators Cross Join (Cross Product) and Natural Join in a relational algebra statement?
halapgos1
  • 1,130
  • 4
  • 16
  • 34
-1
votes
2 answers

How to pivot table and get data in below format

Currently I have data in below As-Is format And have requirement to get in below format I am using SQL 2008 R2 version I have spend some time to get this working using Pivot \ Unpivot, but no luck. It would be great if someone can help me to…
user2827587
  • 231
  • 4
  • 15
-1
votes
1 answer

What's the difference between Inner Join, Cross Join, and Left Outer Join?

If an Inner Join can be thought of as a cross join and then getting the records that satisfy the condition, then a LEFT OUTER JOIN can be thought of as that, plus ONE record on the left table that doesn't satisfy the condition. In other words, it is…
nonopolarity
  • 146,324
  • 131
  • 460
  • 740
-1
votes
2 answers

SQL INNER JOIN implemented as implicit JOIN

Recently, I came across an SQL query which looked like this: SELECT * FROM A, B WHERE A.NUM = B.NUM To me, it seems as if this will return exactly the same as an INNER JOIN: SELECT * FROM A INNER JOIN B ON A.NUM = B.NUM Is there any sane reason…
user3726374
  • 583
  • 1
  • 4
  • 24
-1
votes
1 answer

Is every type of SQL JOIN a subset of CROSS JOIN

I would like to confirm my understanding of what I have researched about JOINS. Is every type of SQL JOIN a subset of CROSS JOIN ? CROSS JOIN you are selecting Cartesian product, so if you have table A (100 rows) and table B (100 rows) you…
sbolla
  • 671
  • 3
  • 22
  • 39
-2
votes
1 answer

SQL query to fetch joined result - cross join?

I have table users - id name email 1 tamaghna tamaghna@g 2 arunima arunima@g 3 rajiv rajiv@g I have another table products - id name price 1 Amul Milk 10.00 2 Amul Butter 20.00 3 Amul Cheese 30.00 And the final table…
-2
votes
1 answer

How to fix GENERATE_ARRAY() produced too many elements BigQuery

select * , row_number() OVER(PARTITION BY user_id,event_datetime_start,event_datetime_end ORDER BY user_id, event_datetime_start, event_datetime_end,dt_watched) rk from `blackout_tv_july` a cross join…
-2
votes
2 answers

t-sql cross join - using one column as parameter in other query

The main query select case when aCalculatedDatefield > XMONTH then 1 else null end as V from ( some nested queries where the aCalculatedDatefield is created) and I want to run it for some months in year 2022 select XMONTH from…
Mironline
  • 2,755
  • 7
  • 35
  • 61
-2
votes
1 answer

SQL grouping together so data does not repeat

Have data in a table, and trying to query it out so the data reads for example like Motrin | mg | 25 | 4 | day | Pain, in one row. from the image...i have them all under the Answer column. My query that i have brings them all out...but it repeats…
-2
votes
1 answer

How to solve STRUCT errors in this query?

I am trying to get 'video IDs/ project code' from different tables and adding them all to my base table. All of the video IDs have a brand name which I tried to get by cross join. I got to the below query and I am getting errors (No matching…
-2
votes
1 answer

What's the difference between a cross join and an inner join with identical filter?

Let's see a cross join: select c1, c2, c3 from t1 cross join t2 where t1.f1 = t2.f2 and let's see an inner join: select c1, c2, c3 from t1 inner join t2 on t1.f1 = t2.f2 What is the difference between the two statements in terms of performance,…
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
1 2 3
35
36