Join in Databases
When data from more than one table in the database is required, a join condition is
used. Rows in one table can be joined to rows in another table according to common
values existing in corresponding columns, that is, usually primary and foreign key
columns. For displaying data from two or more related tables. Write a simple join
condition in the WHERE clause.
Syntax:
SELECT table1.column, table2.column
FROM table1, table2
WHERE table1.column1=table2.column2;
Cartesian Product:
When a join condition is invalid or omitted completely, the result is a Cartesian
product in which all combinations of rows will be displayed. All rows in the first
table are joined to all rows in the second table.
A Cartesian product tends to generate a large number of rows, and its result is rarely
useful. You should always include a valid join condition in a WHERE clause, unless
you have a specific need to combine all rows from all tables.
used. Rows in one table can be joined to rows in another table according to common
values existing in corresponding columns, that is, usually primary and foreign key
columns. For displaying data from two or more related tables. Write a simple join
condition in the WHERE clause.
Syntax:
SELECT table1.column, table2.column
FROM table1, table2
WHERE table1.column1=table2.column2;
Cartesian Product:
When a join condition is invalid or omitted completely, the result is a Cartesian
product in which all combinations of rows will be displayed. All rows in the first
table are joined to all rows in the second table.
A Cartesian product tends to generate a large number of rows, and its result is rarely
useful. You should always include a valid join condition in a WHERE clause, unless
you have a specific need to combine all rows from all tables.
