Basic   SELECT   Statement  http://ecomputernotes.com
"  "  http://ecomputernotes.com Basic   SELECT   Statement  SELECT  * |   { [DISTINCT]   column | expression   [...
http://ecomputernotes.com Selecting All Columns  SELECT *  FROM  departments;
Selecting Specific Columns  SELECT department_id, location_id  FROM  departments;  http://ecomputernotes.com
Writing SQL Statements  "  SQL statements are not case sensitive.  "  SQL statements can be on one or more lines...
Column Heading Defaults  "  i SQL*Plus:  Default heading justification: Center Default heading display: Uppercase  &q...
Arithmetic Expressions  Create expressions with number and date data by  using arithmetic operators.  Operator  Descriptio...
Using Arithmetic Operators  SELECT last_name, salary, salary + 300  FROM  employees;  «  http://ecomputernotes.com
Operator Precedence  _  /  +  *  "M ultiplication and division take priority over  addition and subtraction.  "O...
Operator Precedence  SELECT last_name, salary, 12*salary+100  FROM  employees;  «  http://ecomputernotes.com
Using Parentheses  SELECT last_name, salary, 12*(salary+100)  FROM  employees;  «
Defining a Null Value  "A  null is a value that is unavailable, unassigned,  unknown, or inapplicable.  "A  null...
Null Values  in Arithmetic Expressions  Arithmetic expressions containing a null value  evaluate to null.  SELECT last_nam...
Defining a Column Alias  A column alias:  "  Renames a column heading  "  Is useful with calculations  "  I...
Using Column Aliases  SELECT last_name AS name, commission_pct comm  FROM  employees;  «  SELECT last_name "Name&quot...
Concatenation Operator  A concatenation operator:  "  Concatenates columns or character strings to  other columns  &q...
Using the Concatenation Operator  SELECT  last_name||job_id AS "Employees"  FRO M  employees;  «
Literal Character Strings  "A  literal is a character, a number, or a date  included in the   SELECT   list.  "D...
Using Literal Character Strings  SELECT last_name  ||' is a '||job_id  AS "Employee Details"  FROM  employees;  «
Duplicate Rows  The default display of queries is all rows, including  duplicate rows.  SELECT department_id  FROM  employ...
Eliminating Duplicate Rows  Eliminate duplicate rows by using the   DISTINCT keyword in the   SELECT   clause.  SELECT DIS...
Displaying Table Structure  DESCRIBE employees
 
Upcoming SlideShare
Loading in …5
×

e computer notes - Writing basic sql select statements

414
-1

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
414
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
16
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

e computer notes - Writing basic sql select statements

  1. 1. Basic SELECT Statement http://ecomputernotes.com
  2. 2. " " http://ecomputernotes.com Basic SELECT Statement SELECT * | { [DISTINCT] column | expression [ alias ],...} FRO M table; SELECT identifies what columns FROM identifies which table
  3. 3. http://ecomputernotes.com Selecting All Columns SELECT * FROM departments;
  4. 4. Selecting Specific Columns SELECT department_id, location_id FROM departments; http://ecomputernotes.com
  5. 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. 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. 7. Arithmetic Expressions Create expressions with number and date data by using arithmetic operators. Operator Description + Add - Subtract * Multiply / Divide http://ecomputernotes.com
  8. 8. Using Arithmetic Operators SELECT last_name, salary, salary + 300 FROM employees; « http://ecomputernotes.com
  9. 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. 10. Operator Precedence SELECT last_name, salary, 12*salary+100 FROM employees; « http://ecomputernotes.com
  11. 11. Using Parentheses SELECT last_name, salary, 12*(salary+100) FROM employees; «
  12. 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. 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. 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. 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. 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. 17. Using the Concatenation Operator SELECT last_name||job_id AS "Employees" FRO M employees; «
  18. 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. 19. Using Literal Character Strings SELECT last_name ||' is a '||job_id AS "Employee Details" FROM employees; «
  20. 20. Duplicate Rows The default display of queries is all rows, including duplicate rows. SELECT department_id FROM employees; «
  21. 21. Eliminating Duplicate Rows Eliminate duplicate rows by using the DISTINCT keyword in the SELECT clause. SELECT DISTINCT department_id FROM employees;
  22. 22. Displaying Table Structure DESCRIBE employees

×