Académique Documents
Professionnel Documents
Culture Documents
Select, 156
Simple
data from a single table
Advanced
data from more tables
join sub-queries
Join, 157
Cartesian product
select * from tableA, tableB
all rows in tableA combined with all rows from tableB huge result! seldom useful!!
Equi-join, 158
Joining 2 tables using common attributes [usually primary and foreign keys] Structure
select from tableA, tableB where tableA.PK = tableB.FK
Non-equi-joins, 161
Where clause using operations other than equality
Fig. 7-6, page 162
Outer join
values without matching values are included in the result.
New syntax
SQL99 standard syntax
SQL advanced select using Oracle 6
Result
Department with and without employees are included in the result
New in Oracle 9i (not present in Oracle 8i) No examples in the book! Look in the Oracle SQL documentation for more examples
SQL advanced select using Oracle 8
Self-join, 165
Joining a table with itself.
ER recursive relationship Rel. model foreign key to another attribute in the same relation. same table used twice in the from clause we need to name the two instances of the table (table aliases) select from employee e, employee s where e.supervisorID = s.ID Fig. 7-9 page 165
SQL advanced select using Oracle 9
minus
Sub-query, 174
The where clause in a select statement may contain another select statement (sub-query)!
Fig. 8-1, page 175 Two types of sub-queries
single row
returning a single row of data, and most often a single data item
multiple row
returning more than on row of data
SQL advanced select using Oracle 11
12
update tableName set (columnNames) = (query) where condition delete from tableName where columnName = (query)
SQL advanced select using Oracle 13
Top-N analysis,183
MS Access SQL and SQL Server has a special keyword top
select top 10 attribute Oracle has no such feature, but it can be simulated using the pseudo-column rownum. Fig. 8-14 + 8-15, page 184 sub-query in from clause
inline view [more on views later on]
15
Correlated subquery,185
Ordinary subquery
The inner query does not reference columns from the outer query The inner query can be calculated once and for all.
Correlated subquery
The inner query references columns from the outer query Like programming 2 loops, one inside the other Figure 8-17, page 187
16
True
If the current result of the sub-query is not empty
Examples
Figure 8-18, page 187
At least one student has the faculty (teacher) Select 1
We have to select something, but in this case we dont use it!
Final remarks
SQL (specially select) is like programming.
There's only one place to learn it - at the keyboard!
18