CREATE TABLE student(
id INT(10),
NAME VARCHAR(10),
CONSTRAINT pk_id PRIMARY KEY (id)
);
CREATE TABLE account(
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;