You are here
Home > Sql Server > SQL JOIN (CROSS JOIN)

SQL JOIN (CROSS JOIN)

SQL JOIN

Cross Join:

  • Cross join combine each row from the first table with all rows of the second table.
  • In other words, it performs a multiplication between tables.
  • Cross join is also known as Cartesian Join.
  • Syntax:
  • select column_name(s)

    from table1

    cross join table2

  • We can perform cross join without join clause.
  • Syntax:
  • select column_name(s)

    from table1,table2

  • Database Table: Customers

Cust_id

Name Age City
1 Prince 22

Anand

2

Komal 44 Pune
3 Khusi 30

Delhi

4

Anil 45 Mumbai
5 Abhi 27

Ahmedabad

6

Juhi 35

Baroda

 

  • Database Table: Orders

Order_id

Order_no Price Cust_id
1 1111 1100

2

2

2244 227 2
3 7777 677

4

4

4466 449 4
5 8888 1700

6

 

  • Example:
  • select Name, Age, City,

    Order_id, Order_no, Price

    from Customers

    cross join Orders;

     

    or

     

    select Name, Age, City,

    Order_id, Order_no, Price

    from Customers , Orders;

  • Output:

Name

Age City Order_id Order_no Price
Prince 22 Anand 1 1111

1100

Komal

44 Pune 1 1111 1100
Khusi 30 Delhi 1 1111

1100

Anil

45 Mumbai 1 1111 1100
Abhi 27 Ahmedabad 1 1111

1100

Juhi

35 Baroda 1 1111 1100
Prince 22 Anand 2 2244

227

Komal

44 Pune 2 2244 227
Khusi 30 Delhi 2 2244

227

Anil

45 Mumbai 2 2244 227
Abhi 27 Ahmedabad 2 2244

227

Juhi

35 Baroda 2 2244 227
Prince 22 Anand 3 7777

677

Komal

44 Pune 3 7777 677
Khusi 30 Delhi 3 7777

677

Anil

45 Mumbai 3 7777 677
Abhi 27 Ahmedabad 3 7777

677

Juhi

35 Baroda 3 7777 677
Prince 22 Anand 4 4466

449

Komal

44 Pune 4 4466 449
Khusi 30 Delhi 4 4466

449

Anil

45 Mumbai 4 4466 449
Abhi 27 Ahmedabad 4 4466

449

Juhi

35 Baroda 4 4466 449
Prince 22 Anand 5 8888

1700

Komal

44 Pune 5 8888 1700
Khusi 30 Delhi 5 8888

1700

Anil

45 Mumbai 5 8888 1700
Abhi 27 Ahmedabad 5 8888

1700

Juhi

35 Baroda 5 8888

1700

 

 

Keep visiting my site ask2tech.com for upcoming top technical article

Learn more about DBA at TechNet Consultancy

Leave a Reply

Top