* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download 4a-SQL-Select
Survey
Document related concepts
Oracle Database wikipedia , lookup
Relational algebra wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Concurrency control wikipedia , lookup
Ingres (database) wikipedia , lookup
Functional Database Model wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Versant Object Database wikipedia , lookup
ContactPoint wikipedia , lookup
Clusterpoint wikipedia , lookup
Transcript
CSCI N207 Data Analysis with Spreadsheets 4a. Structured Query Language - SELECT Statement Lingma Acheson Department of Computer and Information Science IUPUI 1 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? – …? 2 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. 3 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. 4 SELECT statement • Select certain columns (and all rows) Example 1, Email list of all employees: SELECT FirstName, LastName, Email FROM EMPLOYEE; Example 2, All projects’ start date and end date, SELECT ProjectName, StartDate, EndDate FROM PROJECT; 5 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. 6 SELECT statement • Select all columns (and all rows) SELECT * FROM EMPLOYEE; (query necessary?) 7 SELECT statement • Select only unique values Example 1, show all the project start dates, remove all the duplicate values SELECT DISTINCT startDate FROM PROJECT; 8