sql中的笛卡爾積

CREATE TABLE student( spa

id INT(10),orm

NAME VARCHAR(10),it

CONSTRAINT pk_id PRIMARY KEY (id)select

);co

CREATE TABLE account(join

id INT(10),

money DOUBLE,

CONSTRAINT pk_id PRIMARY KEY(id)

);

INSERT INTO student VALUES('1','jack');

INSERT INTO account VALUES('1','1.1');

INSERT INTO account VALUES('2','2.1');

INSERT INTO account VALUES('3','2.1');

INSERT INTO account VALUES('4','2.1');

INSERT INTO account VALUES('5','2.1');

INSERT INTO account VALUES('6','2.1');

#產生笛卡爾積

SELECT * FROM student,account;

解決辦法:

1左外鏈接

  select * from student s left join account acc on s.id=acc.id;

2內鏈接

 SELECT * FROM student s INNER JOIN account acc ON s.id=acc.id;

相關文章
相關標籤/搜索