CHAPTER 4. Retrieving Data Using The SQL Select Statement
CHAPTER 4. Retrieving Data Using The SQL Select Statement
Select has the ability to show raw information, but also to edit information before it’s
displayed. It represents the reason that databases exists: to analyze and transform
information.
It can :
perform mathematical analysis on numerical data
perform string manipulation on text data
format raw numbers for financial report
abbreviate lengthy data
sort rows of data according to different data types
aggregate multiple rows of information in various ways
create organizational hierarchies
show summary of data at various levels
join related information from multiple sources and present its findings at various
levels of detail and aggregation
Example of a select syntax:
SELECT select_list
FROM table_expression
[ WHERE ... ]
[ START WITH start_expression ]
CONNECT BY [NOCYCLE] { PRIOR parent_expr = child_expr | child_expr =
PRIOR parent_expr }
[ ORDER SIBLINGS BY column1 [ ASC | DESC ] [, column2 [ ASC | DESC ] ]
...
[ GROUP BY ... ]
[ HAVING ... ]
Test :
1. b. ok
2. b, c. ok
3. b. ok
4. b, c. ok
5. a,b,c ok
6. a,d. ok
7. b ok
8. b no -> C
9. c ok
10. d ok
11. b ok
12. b ok
13. d ok
14. a ok
15. a ok
Tricky questions :
1. How many results does it return the following select statement ?
Select DISTINCT FIRST_NAME, LAST_NAME,ZIP_CODE
2. Is this correct? If yes, what is the result of the selection ?
Select ROWNUM, * FROM CUSTOMERS