SQL Cartesian Product

Source: Internet
Author: User
/*  ========================================================
Description:
Use SQL to implement Cartesian Product
Author: CC
Date: 2011.11.03
======================================================== */

Use Test
Go

Select * From L; -- Such as l
Select * From M; -- Such as m

-- Cross-join implementation, lm
Select * From L Cross Join M;

L table

Lid name
-------------------------------
101 Beijing
102 Taiyuan
101 null
102 null

(Four rows affected)

 

M Table
Matid qty lid mname
-----------------------------------------------------
10011 1 101 Beijing
20012 1 102 Taiyuan
10011 1 102 Taiyuan
10011 1 102 Taiyuan

 

LM:

Lid name matid qty lid mname
------------------------------------------------------------------------------------
101 Beijing 10011 1 101 Beijing
102 Taiyuan 10011 1 101 Beijing
101 null 10011 1 101 Beijing
102 null 10011 1 101 Beijing
101 Beijing 20012 1 102 Taiyuan
102 Taiyuan 20012 1 102 Taiyuan
101 null 20012 1 102 Taiyuan
102 null 20012 1 102 Taiyuan
101 Beijing 10011 1 102 Taiyuan
102 Taiyuan 10011 1 102 Taiyuan
101 null 10011 1 102 Taiyuan
102 null 10011 1 102 Taiyuan
101 Beijing 10011 1 102 Taiyuan
102 Taiyuan 10011 1 102 Taiyuan
101 null 10011 1 102 Taiyuan
102 null 10011 1 102 Taiyuan

(16 rows are affected)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.