Writing Basic SQL SELECT Statements

Slides:



Advertisements
Similar presentations
Virtual training week 4 structured query language (SQL)
Advertisements

1Eyad Alshareef Enhanced Guide to Oracle 10g Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data.
SQL Review Sections 1 - SQL and other basic statements.
LECTURE 8.  Consider the table employee(employee_id,last_name,job_id, department_id )  assume that you want to display all the employees in department.
Writing Basic SQL Statements. Objectives After completing this lesson, you should be able to do the following:  List the capabilities of SQL SELECT statements.
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
Introduction to Oracle9i: SQL1 Basic SQL SELECT Statements.
Restricting and Sorting Data. Consider the table employee(employee_id,last_name,job_id, department_id ) assume that you want to display all the employees.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Writing Basic SQL statement 2 July July July Create By Pantharee Sawasdimongkol.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Chapter 1 Writing Basic SQL Statements Important Legal Notice:  Materials on this lecture are from a book titled “Oracle Education” by Kochhar, Gravina,
Ceng 356-Lab2. Objectives After completing this lesson, you should be able to do the following: Limit the rows that are retrieved by a query Sort the.
Ceng 356-Lab1. Objectives After completing this lesson, you should be able to do the following: Get Familiar with the development environment List the.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Chapter 2 Basic SQL SELECT Statements
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
1 Copyright © 2006, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Copyright  Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
Restricting and Sorting Data. ◦ Limiting rows with:  The WHERE clause  The comparison conditions using =,
2 Copyright © Oracle Corporation, All rights reserved. Restricting and Sorting Data.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
4 Copyright © 2006, Oracle. All rights reserved. Restricting and Sorting Data.
LECTURE 8.  Consider the table employee(employee_id,last_name,job_id, department_id )  assume that you want to display all the employees in department.
After completing this lesson, you should be able to do the following: List the capabilities of MySQL SELECT statements Execute a basic SELECT statement.
SQL (DDL & DML Commands)
2 Writing Basic SELECT Statements. 1-2 Copyright  Oracle Corporation, All rights reserved. Capabilities of SQL SELECT Statements Selection Projection.
Copyright  Oracle Corporation, All rights reserved. Writing Basic SQL Statements.
RELATSIOONILISED ANDMEBAASID(alg) SQLi VÕIMALUSED.
27 Oktober 2015BASIS DATA I/2009-GENAP1 SQL SELECT STATEMENT BASIS DATA I/2009-GENAP Oleh Satrio Agung Wicaksono, S.Kom., M.Kom.
Oracle 11g DATABASE DEVELOPMENT LAB1. Introduction  Oracle 11g Database:-  Oracle 11g database is designed for some features, which helps to the organizations.
Introduction to SQL PART Ⅰ 第一讲 Writing Basic SQL SELECT Statements.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
1 Writing Basic SQL Statements. 1-2 Objectives At the end of this lesson, you should be able to: List the capabilities of SQL SELECT statements Execute.
2 第二讲 Restricting and Sorting Data. Objectives After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
Queries SELECT [DISTINCT] FROM ( { }| ),... [WHERE ] [GROUP BY [HAVING ]] [ORDER BY [ ],...]
I-1 Copyright س Oracle Corporation, All rights reserved. Data Retrieval.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
1 Chapter 2 Basic SQL SELECT Statements. 2 Chapter Objectives Distinguish between an RDBMS and an ORDBMS Identify keywords, mandatory clauses, and optional.
1-1 Copyright  Oracle Corporation, All rights reserved. Logging In to SQL*Plus From Windows environment:From Windows environment: From command line:From.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
Writing Basic SQL Statements. Objectives After completing this lesson, you should be able to do the following: –List the capabilities of SQL SELECT statements.
Writing Basic SQL SELECT Statements Lecture
1 Copyright © 2007, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Oracle 10g Retrieving Data Using the SQL SELECT Statement.
1 Copyright © 2009, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Copyright س Oracle Corporation, All rights reserved. 1 Writing Basic SQL Statements.
1 Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement.
Restricting and Sorting Data
RELATSIOONILISED ANDMEBAASID (algus , ORACLE materjalid)
Retrieving Data Using the SQL SELECT Statement
Writing Basic SQL SELECT Statements
Writing Basic SQL SELECT Statements
Basic select statement
Using the Set Operators
Writing Basic SQL SELECT Statements
Using the Set Operators
Retrieving Data Using the SQL SELECT Statement
Restricting and Sorting Data
“Manipulating Data” Lecture 6.
“Manipulating Data” Lecture 6.
Writing Basic SQL SELECT Statements
Writing Basic SQL Statements
Retrieving Data Using the SQL SELECT Statement
Displaying Data from Multiple Tables
Restricting and Sorting Data
Presentation transcript:

Writing Basic SQL SELECT Statements Lecture 7 -1

Outlines SQL SELECT statement Capabilities of SELECT statements Basic SELECT statement Selecting all columns Selecting specific columns Arithmetic Expressions Using Arithmetic operators Arithmetic operators precedence NULL values in arithmetic expression Using column aliases Concatenation operator Literal Character String Ghadah Al Hadba

Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT statement, you can do the following: Projection: You can use the projection capability in SQL to choose the columns in a table that you want returned by your query. You can choose as few or as many columns of the table as you require. Selection: You can use the selection capability in SQL to choose the rows in a table that you want returned by a query. You can use various criteria to restrict the rows that you see. Joining: You can use the join capability in SQL to bring together data that is stored in different tables by creating a link between them. Ghadah Al Hadba

Capabilities of SQL SELECT Statements (Cont.) Ghadah Al Hadba

Basic SELECT Statement Select Statement Syntax: SELECT [DISTINCT,*]columns names| expression [alias] FROM table; Note that: SELECT clause identifies what columns to retrieve. FROM clause specifies the table containing the columns listed in the SELECT clause. Ghadah Al Hadba

Basic SELECT Statement Ghadah Al Hadba

Selecting All Columns SELECT * FROM table; Syntax: Means all columns Ghadah Al Hadba

Selecting All Columns (Example) Ghadah Al Hadba

Selecting All Columns (Example) In the example on the slide, the department table contains four columns: DEPARTMENT_ID, DEPARTMENT_NAME, MANAGER_ID, and LOCATION_ID. The table contains eight rows, one for each department. Note That : You can also display all columns in the table by listing all the columns after the SELECT E.g. SELECT department_id, department_name, manager_id, location_ id FROM departments; The previews SQL statement, like the example on the slide, will display all columns and all rows of the DEPARTMENTS table: Ghadah Al Hadba

Selecting Specific Columns You can use the SELECT statement to display specific columns of the table by specifying the column names, separated by commas.(see Example -1-) In the SELECT clause, specify the columns that you want to display in the order in which you want them to appear in the output. (see Example -2-) Ghadah Al Hadba

Example-1- Ghadah Al Hadba

Example-2- . Ghadah Al Hadba

Arithmetic Expressions Create expressions with number and date data, i.e. column names that contains only numeric or date data, by using arithmetic operators operator Description + Add - Subtract * Multiply / Divide Ghadah Al Hadba

Using Arithmetic Operators Ghadah Al Hadba

Using Arithmetic Operators (Cont.) The previews example uses the addition operator to calculate a salary increase of $300 for all employees and displays a new SALARY+300 column in the output. Note that the resultant calculated column SALARY+300 is not a new column in the EMPLOYEES table; it is for display only. Where by default, the name of a new column comes from the calculation that generated it—in this case, (salary+300). Ghadah Al Hadba

Operator Precedence * / + _ * / + _ Multiplication and division take priority over addition and subtraction. Operators of the same priority are evaluated from left to right. Parentheses are used to force prioritized evaluation and to clarify statements. Ghadah Al Hadba

Operator Precedence SELECT last_name, salary, 12*salary+100 FROM employees; SELECT last_name, salary, 12*(salary+100) 1 2 2 1 Why? Ghadah Al Hadba

Null Values in Arithmetic Expressions Arithmetic expressions containing a null value evaluate to null. If any column value in an arithmetic expression is null, the result is null. For example, if you attempt to perform division with zero, you get an error. However, if you divide a number by null, the result is a null or unknown. Ghadah Al Hadba

Null Values in Arithmetic Expressions Ghadah Al Hadba

Using Column Aliases Rename a column heading Is useful with calculations Immediately follows the column name, and there also can be the optional AS keyword between the column and the alias Requires double quotation marks (“ “)if the alias: Contains space Contains a special characters (such as # or $) Is a case sensitive Ghadah Al Hadba

Using Column Aliases (Examples) Ghadah Al Hadba