From now on, the DEPT (department) Table will be used in addition to the existing EMP Table.
DEPTNO | DNAME | LOC |
10 | ACCOUNTING | NEW YORK |
20 | RESEARCH | DALLAS |
30 | SALES | CHICAGO |
40 | OPERATIONS | BOSTON |
SELECT | EMP.EMPNO,EMP.ENAME,DEPT.DEPTNO,DEPT.DNAME |
FROM | EMP,DEPT |
WHERE | EMP.DEPTNO = DEPT.DEPTNO |
When querying from multiple Tables, use a FROM followed by the Table Name separated by "," (comma).
DEPTNO = DEPT.DEPTNO in the WHERE condition, meaning that the columns where DEPTNO in the EMP Table is equal to DEPTNO in the DEPT Table are concatenated.
The reason why the item name immediately following the SELECT statement contains the statement "Table明. The reason for the item name "TableMing. itemName" is to specify which item should be displayed if the Table is concatenated and both Tables have the same item name. (If only "DEPTNO" is specified, the DBMS will not know which item to display and an error will result.)
To further narrow down the criteria from the concatenated Table, write AND EMP.SAL > 1500 in the WHERE condition.
Now for the Practice, I will give you two questions.
SELECT | E.EMPNO,E.ENAME,D.DEPTNO,D.DNAME |
FROM | EMP E,DEPT D |
WHERE | E.DEPTNO = D.DEPTNO |
The above SQL is exactly the same as "conditional join". The difference is that the DB reassignment (alias) is added to the Table to simplify the description.
In practice, however, there are very long table names such as "Total Sales of All Stores at the End of the Previous Month". In such cases, it is very useful.
Now for the Practice, I will give you one Question.
This completes [ Inquiry to multiple tables ].