0% found this document useful (0 votes)
99 views

Experiment #3: Retrieving Data Using The SQL SELECT Statement

This document discusses using SQL SELECT statements to retrieve data from databases. It covers the basic SELECT statement syntax, selecting specific columns or all columns, using column aliases, arithmetic expressions, concatenation operators, and removing duplicate rows with DISTINCT. The procedure section provides 4 sample questions to practice different SELECT statement capabilities like identifying errors, selecting columns with aliases, formatting output, and selecting unique values.

Uploaded by

Feras TheReaper
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Experiment #3: Retrieving Data Using The SQL SELECT Statement

This document discusses using SQL SELECT statements to retrieve data from databases. It covers the basic SELECT statement syntax, selecting specific columns or all columns, using column aliases, arithmetic expressions, concatenation operators, and removing duplicate rows with DISTINCT. The procedure section provides 4 sample questions to practice different SELECT statement capabilities like identifying errors, selecting columns with aliases, formatting output, and selecting unique values.

Uploaded by

Feras TheReaper
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment #3:

Retrieving Data Using the SQL SELECT Statement

Student’s Name:

Semester: Date:

Assessment:

Assessment Point Weight Grade

Methodology and correctness of results

Discussion of results

Participation

Assessment Points’ Grade:

Comments:

Prepared By: Eng.Randa Al-Dallah 1


Experiment #3:
Retrieving Data Using the SQL SELECT Statement

Objectives:
After completing this experiment, you should be able to do the following:
• List the capabilities of SQL SELECT statements
• Execute a basic SELECT statement
• Returns all rows and columns from a table
• Returns specified columns from a table
• Uses column aliases to display more descriptive column headings

Discussion:
SQL has one basic statement for retrieving information from a database: the SELECT statement.
There are many options and flavors to the SELECT statement in SQL, so we will introduce its
features gradually.
The basic syntax of the SELECT statement is:
SELECT *|{[DISTINCT] column|expression [alias],...}
FROM table;

Using the following simple rules and guidelines, you can construct valid statements that are both
easy to read and easy to edit:
• SQL statements are not case sensitive (unless indicated).
• SQL statements can be entered on one or many lines.
• Keywords cannot be split across lines or abbreviated.
• Clauses are usually placed on separate lines for readability and ease of editing.
• Indents should be used to make code more readable.
• Keywords typically are entered in uppercase; all other words, such as table names
and columns, are entered in lowercase.

Prepared By: Eng.Randa Al-Dallah 2


Arithmetic Expressions
In the SELECT statement you can perform a calculations by using arithmetic expressions. An
arithmetic expression can contain column names, constant numeric values, and the arithmetic
operators.

Column Aliases
When displaying the result of a query, normally uses the name of the selected column as the
column heading. This heading may not be descriptive and, therefore, maybe difficult to
understand. You can change a column heading by using a column alias. Specify the alias after the
column in the SELECT list using a space as a separator. By default, alias headings appear in
uppercase. If the alias contains spaces or special characters (such as # or $), or if it is case
sensitive, enclose the alias in double quotation marks (" ").

Concatenation Operator
You can link columns to other columns, arithmetic expressions, or constant values to create a
character expression by using the concatenation operator (||). Columns on either side of the
operator are combined to make a single output column. If you concatenate a null value with a
character string, the result is a character string.

Duplicate Rows
The SQL displays the results of a query without eliminating duplicate rows. To eliminate duplicate
rows in the result, include the DISTINCT keyword in the SELECT clause immediately after the
SELECT keyword.

Prepared By: Eng.Randa Al-Dallah 3


Procedure:
Exercises:

Q1: There are four coding errors in the following statement. Can you identify
them?
SELECT empno, ename
salary x 12 ANNUAL SALARY
FROM emp;

The correct SELECT statement:

Q2: Display the employee name, job, hire date, and employee number for each
employee, with employee number appearing first. Provide an alias STARTDATE
for the HIREDATE column.

Q3: Display all the data from that EMP table. Separate each column output by a
comma. Name the column title THE OUTPUT

Q4: Display all unique jobs from the EMP table

Prepared By: Eng.Randa Al-Dallah 4

You might also like