Академический Документы
Профессиональный Документы
Культура Документы
Page 1 of 5
After completing this topic, you should be able to discuss and write basic SELECT SQL statements.
Note
SQL statements are made up of clauses, each of which begins with a SQL keyword. It's common practice to enter each SQL clause on a separate line and to use indenting to enhance readability.
You retrieve information from a database using a SELECT SQL statement. You can use a SELECT statement to create SQL queries that return specific rows or columns from a table. You can also use a SELECT statement to link data stored in different tables. The basic SELECT syntax is
In this syntax, column|expression is the information you want to retrieve and table is the table that contains the information. You need to terminate SQL statements with a semicolon, although this isn't necessary in iSQL.
Question
http://xlibrary.skillport.com/courseware/cbtlib/66155/67612/eng/thin/transcript.html
5/11/2007
Page 2 of 5
You can add a WHERE clause to a SELECT statement. What do you think you use the WHERE clause to do? Options: 1. 2. 3. 4. To specify the database in which a table resides To specify search criteria for a query To specify a network node to search on To specify the disk in your computer that contains the table you want to query
Answer
You use the WHERE clause to specify search criteria for a query. The system will then return only those results that meet with the criteria.
To display all the columns in a table, you can use an asterisk (*) instead of entering each column name. To display all columns in the jobs table, for example, you execute the following code.
Let's say that you want to display only the job_title and max_salary columns from the jobs table. To do this, you enter each column name separated by a comma.
DESCRIBE employees
Note
http://xlibrary.skillport.com/courseware/cbtlib/66155/67612/eng/thin/transcript.html
5/11/2007
Page 3 of 5
Question
What command do you use to list all the columns in a table? Options: 1. DESCRIBE 2. SELECT 3. WHERE
Answer
You use the DESCRIBE command to list all the columns in a table. Option 1 is correct. You use the DESCRIBE command if you need to view the structure of a table. The DESCRIBE command lists all the columns in a table, as well as the specified data type for each column. Option 2 is incorrect. You use a SELECT SQL statement to retrieve information from a database. You can use a SELECT statement to create SQL queries that return specific rows or columns from a table. You can also use a SELECT statement to link data stored in different tables. Option 3 is incorrect. You use the WHERE clause within a SELECT statement to specify search criteria for a query. The system will then return only those results that meet with the criteria.
3. Arithmetic expressions
You can use arithmetic operators to modify the way data is displayed or to perform calculations. You can use column names and constant numeric values to build arithmetic expressions.
l l l l
http://xlibrary.skillport.com/courseware/cbtlib/66155/67612/eng/thin/transcript.html
5/11/2007
Page 4 of 5
+ Add This code adds 100 to whatever value the salary column returns. SELECT salary, salary+100 FROM employees; Subtract This code subtracts 500 from whatever value the salary column returns. SELECT salary, salary500 FROM employees; * Multiply This code multiplies the value returned by the salary column by 1.2, effectively increasing it by 20 percent. SELECT salary, salary*1.2 FROM employees; / Divide This code divides the value returned by the salary column in half. SELECT salary, salary/2 FROM employees;
In expressions that contain more than one operator, multiplication and division take a higher priority than addition and subtraction. If two operators with the same priority appear in an expression, SQL evaluates and executes them from left to right. However, you can force an expression to be evaluated first by putting it in parentheses. If a row of data is missing a value for a specific column, that value is null. Null is an unavailable, unassigned, unknown, or inapplicable value. Null is not the same as zero which is a number or as a space which is a character. If an arithmetic expression encounters a null value, the result is always null. You can designate a column in a table as NOT NULL. This means that Oracle won't accept a row of data for insertion into the table if the NOT NULL field doesn't contain a value.
Summary
You use Structured Query Language (SQL) to define and manipulate relational databases. You can retrieve data from tables in a database using a SELECT SQL statement. You can use the DESCRIBE command to view the structure of a table. The output of this command lists the name of each column alongside the type of data that the column contains. SQL supports standard arithmetic operators for addition, subtraction, multiplication, and division. Multiplication and division are evaluated before addition and subtraction. If an arithmetic expression encounters a null value, the result will always be null.
http://xlibrary.skillport.com/courseware/cbtlib/66155/67612/eng/thin/transcript.html
5/11/2007
Page 5 of 5
Table of Contents
| Top of page | | Learning objective | | 1. The basic SELECT statement | | 2. Displaying table structure | | 3. Arithmetic expressions | | Summary |
Copyright 2003 SkillSoft. All rights reserved. SkillSoft and the SkillSoft logo are trademarks or registered trademarks of SkillSoft in the United States and certain other countries. All other logos or trademarks are the property of their respective owners.
http://xlibrary.skillport.com/courseware/cbtlib/66155/67612/eng/thin/transcript.html
5/11/2007