Difference between revisions of "Database Queries"
Jump to navigation
Jump to search
Line 10: | Line 10: | ||
; SELECT fristname || ' ' || lastname "Customer Name" FROM table name | ; SELECT fristname || ' ' || lastname "Customer Name" FROM table name | ||
: this will add a alias for the column heading called Customer Name | : this will add a alias for the column heading called Customer Name | ||
:SELECT title AS "Title of Book", category FROM books; | |||
; This adds the column alias "Title of Book" to the results instead of using just the title as the column heading | |||
== Creating Calculated Fields in a Query == | |||
SELECT title, retail*cost as profit FROM books; | |||
retail column is multiplied by cost and the result is displayed in the alias field profit | |||
[[#Select Command|Back To Top]]-[[Main_Page| Home]] - [[Oracle_SQL|Category]] | [[#Select Command|Back To Top]]-[[Main_Page| Home]] - [[Oracle_SQL|Category]] |
Revision as of 22:34, 4 October 2017
Select Command
- SELECT * from tableName
- SELECT all columns FROM the table
- SELECT column1, column2 FROM tableName
- SELECT 2 columns FROM the tableName table
- SELECT DISTINCT column FROM tableName
- will display only unique results (no duplicates)
- SELECT firstname || ' ' || lastname FROM tablename
- will concatenate first and last name into one field (the ' ' between the || inserts a space)
- SELECT fristname || ' ' || lastname "Customer Name" FROM table name
- this will add a alias for the column heading called Customer Name
- SELECT title AS "Title of Book", category FROM books;
- This adds the column alias "Title of Book" to the results instead of using just the title as the column heading
Creating Calculated Fields in a Query
SELECT title, retail*cost as profit FROM books; retail column is multiplied by cost and the result is displayed in the alias field profit