e computer notes - Writing basic sql select statements

  • 323 views
Uploaded on

 

More in: Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
323
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
12
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Basic SELECT Statement http://ecomputernotes.com
  • 2. " " http://ecomputernotes.com Basic SELECT Statement SELECT * | { [DISTINCT] column | expression [ alias ],...} FRO M table; SELECT identifies what columns FROM identifies which table
  • 3. http://ecomputernotes.com Selecting All Columns SELECT * FROM departments;
  • 4. Selecting Specific Columns SELECT department_id, location_id FROM departments; http://ecomputernotes.com
  • 5. Writing SQL Statements " SQL statements are not case sensitive. " SQL statements can be on one or more lines. " Keywords cannot be abbreviated or split across lines. " Clauses are usually placed on separate lines. " Indents are used to enhance readability. http://ecomputernotes.com
  • 6. Column Heading Defaults " i SQL*Plus: Default heading justification: Center Default heading display: Uppercase " SQL*Plus: Character and Date column headings are left- justified Number column headings are right-justified Default heading display: Uppercase http://ecomputernotes.com
  • 7. Arithmetic Expressions Create expressions with number and date data by using arithmetic operators. Operator Description + Add - Subtract * Multiply / Divide http://ecomputernotes.com
  • 8. Using Arithmetic Operators SELECT last_name, salary, salary + 300 FROM employees; « http://ecomputernotes.com
  • 9. Operator Precedence _ / + * "M ultiplication and division take priority over addition and subtraction. "O perators of the same priority are evaluated from left to right. "P arentheses are used to force prioritized evaluation and to clarify statements. http://ecomputernotes.com
  • 10. Operator Precedence SELECT last_name, salary, 12*salary+100 FROM employees; « http://ecomputernotes.com
  • 11. Using Parentheses SELECT last_name, salary, 12*(salary+100) FROM employees; «
  • 12. Defining a Null Value "A null is a value that is unavailable, unassigned, unknown, or inapplicable. "A null is not the same as zero or a blank space. SELECT last_name, job_id, salary, commission_pct FROM employees; « «
  • 13. Null Values in Arithmetic Expressions Arithmetic expressions containing a null value evaluate to null. SELECT last_name, 12*salary*commission_pct FROM employees; « «
  • 14. Defining a Column Alias A column alias: " Renames a column heading " Is useful with calculations " Immediately follows the column name - there can also be the optional AS keyword between the column name and alias "R equires double quotation marks if it contains spaces or special characters or is case sensitive
  • 15. Using Column Aliases SELECT last_name AS name, commission_pct comm FROM employees; « SELECT last_name "Name", salary*12 "Annual Salary" FROM employees; «
  • 16. Concatenation Operator A concatenation operator: " Concatenates columns or character strings to other columns " Is represented by two vertical bars (||) " Creates a resultant column that is a character expression
  • 17. Using the Concatenation Operator SELECT last_name||job_id AS "Employees" FRO M employees; «
  • 18. Literal Character Strings "A literal is a character, a number, or a date included in the SELECT list. "D ate and character literal values must be enclosed within single quotation marks. "E ach character string is output once for each row returned.
  • 19. Using Literal Character Strings SELECT last_name ||' is a '||job_id AS "Employee Details" FROM employees; «
  • 20. Duplicate Rows The default display of queries is all rows, including duplicate rows. SELECT department_id FROM employees; «
  • 21. Eliminating Duplicate Rows Eliminate duplicate rows by using the DISTINCT keyword in the SELECT clause. SELECT DISTINCT department_id FROM employees;
  • 22. Displaying Table Structure DESCRIBE employees
  • 23.