Cartesian products of two sets in Mathematics and how it is related to Cross Join in Sql server ?


Today i want to discuss the Cartesian products of two sets in Mathematics and how it is related to Cross Join in SQL-Server. This is the article i want to explain here with mathematical example and sql server query with Code snippets

Today i want to introduce the Cartesian products of two sets in Mathematics and how it is related to Cross Join of two tables in Structured Query Language (SQL - SERVER). This is the article i want to explain here in this.

Let us say A and B are two Disjoint sets say A has a set of pairs A= {3,4}; and B = {4,5} it will result with all ordered pairs.

what will be the Cartesian products of these two Disjoint sets

If we have done Cross Join between A * B

A × B = {3,4} × {4,5} = {(3,4), (3,5), (4,4), (4,5)}
B × A = {4,5} × {3,4} = {(4,3), (4,4), (5,3), (5,4)}

A = B = {4,4}

Cross Join between two tables :

Tab1e : 1 ColName1Students

Table :2 ColName2Students



Select * from ColName1Students Cross Join ColName2Students





Select * from ColName1Students , ColName2Students




ColName1Students Table Contains

StudName

Bhushan
Srirama
rakesh

ColName2Students

studName

ravi
raj
ram


Resultset of the two tables is....

Bhushan
srirma
ravi
raj
ram
rakesh


Note :

When you apply cross join between two tables they need to have same cordial of Columns and same column names.

Computer science is a branch in Mathematics (Tree) (Many people may disagree with this and dislike this but there are many proofs and evidences as the above).Many of the Relations,functions, Sets even Group theory and Ring Theory like many a Theories are used in Databases and Programming Languages. From the above example it is quite evident that the Cartesian Product of two Sets is equal to Cross Join of two tables.


Article by srirama
A Good advice from parent to a Child , Master to a Student , Scholar to an Ignorant is like a doctor prescribed pill it is bitter to take but when they take it will do all good for them --- Bhushan

Follow srirama or read 74 articles authored by srirama

Comments

Author: Sridhar Thota03 May 2015 Member Level: Gold   Points : 4

Cross join on single table:

1.Let us conder a table called TEAMS.
which has seven different countries under the column named CountryName.
TEAMS
--------------------------
CountryName
--------------------------
India
Australia
South Africa
Srilanka
Pakistan
Newzeland
West Indies
---------------------------

2.Fixtures of playing teams with opponents can be achieved using cross join on TEAMS table.


SELECT A.CountryName as Team1, B.CountryName as Team2
FROM TEAMS A
CROSS JOIN TEAMS B
WHERE A.CountryName ! = B.CountryName


Regards

Sridhar.
DNS Member.
"Hope for the best.. Prepare for the worst.."



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: