lec 3 Flashcards
table level of an sql search
get all data in a table
ex. Select * from Employees
record level of an sql search
get a particular record from a table
select * from Employees where EmployeeNO = 977
slice and dice
get selected records from a table
get selected attributes for all records from a table
get selected attributes from all records from a table
Problems with Select *
gives all attributes in whatever order their stored internally
- might not be order your expecting
- might include attributes your not expecting
If someone adds that attribute you would also get that attribute
Format of a query
SELECT (DETERMINES OUTPUT)
FROM (LIST OF TABLES(source of data))
WHERE (CONDITIONS (determine records selected))
- results in a table
Renaming headings
add AS to each attribute in select clause
ex. SELECT XXXX AS XXX
In Modifying results….
You should be able to use any properly formed expression that evaluates to a single value as one of the attributes in a select
Some SQL operations
determines the first position, if any, at which one string, S1, occurs within another, S2.
returns the length of a given character string.
(truncate)
Data typing in a select
is based on the most appropriate data type available for the individual attribute
- data type of an individual attribute is based on its data definition
- data type of a computed value is established implicitly based on the data types involved in the computation
implicit type conversions can occur in
expressions, fetch operations, single row select operations, inserts, deletes and updates
CAST operator
SPECIFIES EXPLICIT TYPE CONVERSIONS
- allows you to change between reals and integers when presenting data
Sorting results
Add order by
Add Desc for reverse order
summarizing results
use distinct and correct
- distinct will give you a short listing of which types are in there (getting a set of different values of an attribute)
- adding distinct forces sql processor to add unique rows
Group by clause
creates a seperate group for each distinct value of some attribute
having clause
restricts members in a group based on some conditions