文件名称:什么是连接?-SQL语言基础
文件大小:5.26MB
文件格式:PPT
更新时间:2024-05-15 13:24:56
SQL 基础
什么是连接? * SELECT table1.column, table2.column FROM table1, table2 WHERE table1.column1 = table2.column2; 用一个连接来从多个表中获取数据. 在Where子句中书写连接的条件. 如果某个列的名字在多个表中出现了,那么需要在列的名字前面加上表名作为前缀. * Defining Joins When data from more than one table in the database is required, a join condition is used. Rows in one table can be joined to rows in another table according to common values existing in corresponding columns, that is, usually primary and foreign key columns. To display data from two or more related tables, write a simple join condition in the WHERE clause. In the syntax: table1.column denotes the table and column from which data is retrieved table1.column1 = is the condition that joins (or relates) the tables together table2.column2 Guidelines When writing a SELECT statement that joins tables, precede the column name with the table name for clarity and to enhance database access. If the same column name appears in more than one table, the column name must be prefixed with the table name. To join n tables together, you need a minimum of (n-1) join conditions. Therefore, to join four tables, a minimum of three joins are required. This rule may not apply if your table has a concatenated primary key, in which case more than one column is required to uniquely identify each row. For more information, see Oracle Server SQL Reference Manual, Release 8, “SELECT.”