80 likes | 181 Views
CSCI N207 Data Analysis with Spreadsheets. 4 a . Structured Query Language - SELECT Statement. Lingma Acheson Department of Computer and Information Science IUPUI. WPC Database.
E N D
CSCI N207 Data Analysis with Spreadsheets 4a. Structured Query Language- SELECT Statement Lingma Acheson Department of Computer and Information Science IUPUI
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? • …?
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.
SELECT statement • Used to display some data retrieved from the database • Basic frame SELECTColumnName(s) FROMTABLENAME; - 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.
SELECT statement • Select certain columns (and all rows) Example 1, Email list of all employees: SELECTFirstName, LastName, Email FROM EMPLOYEE; Example 2, All projects’ start date and end date, SELECTProjectName, StartDate, EndDate FROM PROJECT;
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.
SELECT statement • Select all columns (and all rows) SELECT * FROM EMPLOYEE; (query necessary?)
SELECT statement • Select only unique values Example 1, show all the project start dates, remove all the duplicate values SELECTDISTINCTstartDate FROM PROJECT;