日期:2014-05-16 浏览次数:20344 次
概念,大道理不多说了,是个IT人都知道内连接、左外连接与右外连接怎么回事,本文目的是为了方便理解和记忆,所以一切的前提都是为了简易方便,当然碰到复杂的问题,要具体问题具体分析。
?
CREATE TABLE STUDENT ( SID INTEGER, NAME VARCHAR(20) NOT NULL, CONSTRAINTS STUDENT_SID_PK PRIMARY KEY(SID) );
?
CREATE TABLE EXAM ( EID INTEGER, SCORE NUMBER(2) NOT NULL, CONSTRAINTS STUDENT_EXAM_EID_FK FOREIGN KEY(EID) REFERENCES STUDENT(SID) );
?
INSERT INTO STUDENT(SID, NAME) VALUES(1, 'Struts'); INSERT INTO STUDENT(SID, NAME) VALUES(2, 'Spring'); INSERT INTO STUDENT(SID, NAME) VALUES(3, 'Hibernate');
INSERT INTO EXAM(EID, SCORE) VALUES(1, 99); INSERT INTO EXAM(EID, SCORE) VALUES(2, 88);
?
?
SELECT S.SID, S.NAME, E.EID, E.SCORE FROM STUDENT S INNER JOIN EXAM E ON S.SID = E.EID;
?
左连接(显示join 左边的表的所有数据)?
SELECT S.SID, S.NAME, E.EID, E.SCORE FROM STUDENT S LEFT OUTER JOIN EXAM E ON S.SID = E.EID;
SELECT S.SID, S.NAME, E.EID, E.SCORE FROM STUDENT S RIGHT OUTER JOIN EXAM E ON S.SID = E.EID;
?
?