Upload
jemimah-bradford
View
216
Download
2
Embed Size (px)
Citation preview
1
4a. Structured Query Language- SELECT Statement
Lingma AchesonDepartment of Computer and Information Science
IUPUI
CSCI N207 Data Analysis with Spreadsheets
2
WPC Database
• What information do we need to retrieve from the database in order to complete some administrative tasks, or help making business decisions?– Who are the employees from the Production
department? – How many employees are there in the
company?– Can you give me the contact info for Heather
Jones?– Who is working on project 1300? – …?
3
Structured Query Language
• Structured Query Language (SQL):– used to query and modify database data
• Using SQL– Show partial information– Connect related information from different
tables– Perform some computation– Process information more efficiently
• SQL is a language used to send command to a database. Must follow some grammar rules.
4
SELECT statement
• Used to display some data retrieved from the database
• Basic frame
SELECT ColumnName(s)
FROM TABLENAME; - Meaning: “Display this (or these) column(s)
from that table (all the rows will show).”• The letters in red are keywords (reserved for the
database to use). They are case-insensitive.
5
SELECT statement
• Select certain columns (and all rows)Example 1, Email list of all employees:SELECT FirstName, LastName, EmailFROM EMPLOYEE;Example 2, All projects’ start date and end date,SELECT ProjectName, StartDate, EndDateFROM PROJECT;
6
SELECT statement
• Save a query and give it a meaningful name if the query needs to be executed repeatedly. E.g. AllEmployeeEmail
• A query can be viewed just like a table, but it’s just a real time snapshot of the table data.
• Any update to the table will be reflected in the query.
• Queries are also called views in some database systems.
7
SELECT statement
• Select all columns (and all rows)SELECT *FROM EMPLOYEE;(query necessary?)
8
SELECT statement
• Select only unique valuesExample 1, show all the project start dates, remove all the duplicate valuesSELECT DISTINCT startDateFROM PROJECT;