【正文】
網(wǎng)絡(luò) 數(shù)據(jù)庫 技 術(shù) 及 應(yīng) 用(主 講 人:潘大四) select student.* , sc.* from student , sc where = 網(wǎng)絡(luò) 數(shù)據(jù)庫 技 術(shù) 及 應(yīng) 用(主 講 人:潘大四) 聯(lián)接查詢 Sno Sname Ssex Sage Sdept 202208101 陳麗 女 20 信管系 202208102 王燕美 女 20 信管系 202208103 丁利 女 20 信管系 Sno Cno Cmark 202208101 1 90 202208101 2 95 202208103 2 90 Student SC 網(wǎng)絡(luò) 數(shù)據(jù)庫 技 術(shù) 及 應(yīng) 用(主 講 人:潘大四) 聯(lián)接查詢結(jié)果 Sname Ssex Sage Sdept Cno Cmark 202208101 陳麗 女 20 信管系 202208101 1 90 202208101 陳麗 女 20 信管系 202208101 2 95 202208103 丁利 女 20 信管系 202208101 2 90 網(wǎng)絡(luò) 數(shù)據(jù)庫 技 術(shù) 及 應(yīng) 用(主 講 人:潘大四) ? (2)Joining in the WHERE clause(自然聯(lián)接 ) SELECT Product, Category FROM tblProduct, tblCategory WHERE = ? Using JOIN ? The SQL92 standard introduced a new notation for joining, using the JOIN condition: ? independent of the WHERE clause. This makes the query easier to read, and SQL Server can decipher and execute it more efficiently (WHEREclause joins are translated into FROMclause joins by SQL Server). ? While the JOIN condition notation is the preferred method of creating join queries, the oldstyle WHERE notation is still used in certain circumstances, such as subqueries. Whenever possible, use the JOIN condition notation over the WHERE notation, but at the same time, be aware that the older style is still used. SELECT , FROM tblProduct inner JOIN tblCategory ON = 網(wǎng)絡(luò) 數(shù)據(jù)庫 技 術(shù) 及 應(yīng) 用(主 講 人:潘大四) 連接查詢 Join Left Join Right Join 網(wǎng)絡(luò) 數(shù)據(jù)庫 技 術(shù) 及 應(yīng) 用(主 講 人:潘大四) Inner Join StuID StuName 1 a 2 b 3 c StuID Cno 1 3 2 4 tblStudent tblCourse select * from tblStudent inner join tblCourse on tblStudent. StuID = tblCourse. StuID 這個(gè)語法是連接查詢中的內(nèi)連接,它產(chǎn)生的結(jié)果是 兩個(gè)表相匹配的記錄出現(xiàn)在結(jié)果列表中。 交叉聯(lián)接返回左表中的所有行,左表中的每一行與右表中的所有行組合。如果表之間有匹配行,則整個(gè)結(jié)果集行包含基表的數(shù)據(jù)值。 完整外部聯(lián)接返回左表和右表中的所有行。如果右表的某行在左表中沒有匹配行,則將為左表返回空值。 右向外聯(lián)接是左向外聯(lián)接的反向聯(lián)接。如果左表的某行在右表中沒有匹配行,則在相關(guān)聯(lián)的結(jié)果集行中右表的所有選擇列表列均為空值。 在 FROM 子句中指定外聯(lián)接時(shí),可以由下列幾組關(guān)鍵字中的一組指定: