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
0
votes
1 answer

How to group a set of row from a table by every possible combination of 3 other tables?

Here are the table structures Table A (id, name) Table B (id, A-id) Table C (id, quantity, B-id, D-id) Table D (id, E-id, F-id) Table E (id, name) Table F (id, name) I want to get the result like this A.name | E.name | F.name | SUM(C.quantity)…
William Wino
  • 3,599
  • 7
  • 38
  • 61
0
votes
2 answers

MDX: Crossjoin and set evaluation

I'm struggling with this MDX that on rows should return crossjoin of Date and Countries sorted by value. Apparently, "[Date].[Fiscal Year].CurrentMember" in Order function during crossjoin is still returning default member, not the current member…
Endokr
  • 98
  • 5
0
votes
2 answers

Create new table from average of multiple columns in multiple tables

I have the following query: CREATE TABLE Professor_Average SELECT Instructor, SUM( + instreffective_avg + howmuchlearned_avg + instrrespect_avg)/5 FROM instreffective_average, howmuchlearned_average, instrrespect_average GROUP BY Instructor; It is…
0
votes
2 answers

MDX adding together two cube measures across two role playing dimensions

I have two queries which I would like to join together,which would give me the calculated total of the row. The problem I have is that although the measures are from 1 fact table the Squad names are in two role playing dimensions. I'm extremely new…
0
votes
2 answers

permutation and combination

i have a table with only one column consisiting of 5 colours- colour ------- red black white green orange I want to get all the combinations like (red,orange) (black,white) . . . etc except the identical ones.i have tried to cross join the table…
shishir_bindu
  • 53
  • 1
  • 7
0
votes
2 answers

Cross Join with always the same string message

I am using Microsoft SQL Server 2005. I would like to have a table in output with a column regarding duplicate values in cross join with a table containing only a column with the same string message. I think the cross join with a "string message"…
TPPZ
  • 4,447
  • 10
  • 61
  • 106
0
votes
1 answer

Is it possible to use CROSS JOIN + INNER and/or OUTER join on Access 2003? If so, how? Probably also needs subquery...?

I have a database with several tables: [Plan Revenue], [Plan Revenue Expense], [Support Provider], [Z Service Codes New] I've already got a query written that will give me a count of how many expense records are listed for each provider in specific…
0
votes
2 answers

Grouping in MDX Query

I am very newbie to MDX world.. I want to group the Columns based on only 3 rows. But, need join for 4th row also.. My query is : SELECT ( { [Measures].[Live Item Count] } ) DIMENSION PROPERTIES parent_unique_name ON COLUMNS,…
Bharathi
  • 1,015
  • 13
  • 41
0
votes
2 answers

Choose minumum result of SELECT query in Postgresql

I have the following query where I want to calculate the closest user to a building of type "store": WITH y AS ( SELECT t.userid as us, ST_Distance(t.thegeometry,b.thegeomtry) as dist FROM track t,buildings b WHERE b.type = 'store' ) SELECT us…
Lily
  • 816
  • 7
  • 18
  • 38
0
votes
1 answer

Handling different conditions present in table parameter to work as "AND" instead of "OR"

I have a page where user dynamically add search condition(s) to filter out records. I am sending those conditions to stored proc in a TVP. Now i need to write a query which applies those filters work as "AND" instead of "OR" Consider an example of…
Sandeep Polavarapu
  • 382
  • 1
  • 6
  • 25
0
votes
1 answer

hibernate and Sybase error

I use hibernate and sybase in my project,the sql which generated by hibernate used cross join,but sybase do not support cross join,can anyone tell me how can I avoid cross join? thanks
-1
votes
1 answer

Cross joins purpose in SQL

I'm having a hard time understanding when a cross join would be useful in SQL. When learning about it, I have seen example that show what it does but those examples haven't been concrete. An example would be helpful.
nants
  • 1
-1
votes
1 answer

How can I write a PostgreSQL and Python command from cleaning this original table to result table as shown below?

In PostgreSQL, I tried the function trim(unnest(string_to_array to clean and distribute to rows but it will not distribute each value to each other (user_id and dates).
Mela
  • 1
-1
votes
1 answer

How to join a sql table with another where each value in one that matches repeats the amount of row in the other one?

Table 1: zipCode Brand 11111 Toyota Table 2: zipCode Dealers 11111 SouthDealer 22222 NorthDealer 33333 EastDealer If I do a left join on zipCode then I get zipCode Brand Dealers 11111 Toyota SouthDealer 22222 …
tmd13
  • 55
  • 2
  • 6
-1
votes
1 answer

Sqlite SQL Statement Not Working As I Expecting

Im using sqlite3 database and i try to get data from two table with cross join. They have some foreign keys and i can`t get reference value for currency names (b_currency and s_currency). They need to be like 'USD','EUR','TRL' etc. SQL…
Zübeyir
  • 53
  • 5