Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (55.6k points)
edited by

Can anyone tell me how to join two tables without a common column in SQL?

2 Answers

0 votes
by (119k points)
edited by

We can use the Cartesian product, union, and cross-product to join two tables without a common column.

Cartesian product means it matches all the rows of table A with all the rows of table B. Here are the syntax to do a Cartesian product for two tables:

SELECT * FROM tableA, tableB;

Union returns the combination of result sets of all the SELECT statements. The following is the query to use Union operator:

SELECT column_list FROM tableA

UNION

SELECT column_list FROM tableB

Here is the syntax to use CROSS JOIN to combine two tables when a particular condition is met”

SELECT tableA.Column1, tableB.Column1

FROM tableA

CROSS JOIN tableB

WHERE tableB.Column1 = ‘value’;

You can go through this SQL tutorial by Intellipaat to learn more such SQL tips and tricks.

You can learn in-depth about SQL statements, queries and become proficient in SQL queries by enrolling in our industry-recognized SQL training.

0 votes
by (3.1k points)

In situations where there is no common column in SQL tables, CROSS JOIN or a JOIN on non-common columns can be resorted to. 


1. Inserting CROSS JOINS

In a CROSS JOIN, every record in the first table is united with all records in the second table, hence forming the Cartesian Product.

For Example:

SELECT * FROM table1 CROSS JOIN table2;

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...