CS 111 – Nov. 10 Structured Query Language (SQL) –We’ve already seen simple select statements, with optional “where” clause and aggregate functions. –More.

Slides:



Advertisements
Similar presentations
Chapter 6 UNDERSTANDING AND DESIGNING QUERIES AND REPORTS.
Advertisements

Start First step Create a new blank database Create a database using the option that will enable you to build your database using pre-set options. Save.
Create a new blank database First step SUBMITTry again.
LECTURE 10.  Group functions operate on sets of rows to give one result per group.
Instructor: Craig Duckett CASE, ORDER BY, GROUP BY, HAVING, Subqueries
Structured Query Language SA0951a: Introduction to SQL Structured Query Language Lots of SQL books in library and ebrary e.g. Head First SQL, SQL for Mere.
Table design screen Field name Data type Field size Other properties.
1 Creating a Non-Conditional List A- What are you going to do? You will “list” “all of the records” in a database. (it means you will not use any condition!)
SQL Intermediate Workshop Authored by Jay Mussan-Levy.
Interpreting SQL Code. SQL (The language used to query a database) S is used to specify the you want to include. F is used to specify the the selected.
1 Working with MS SQL Server II. 2 The sqlcmd Utility Command line utility for MS SQL Server databases. Previous version called osql Available on classroom.
Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall.1 Exploring Microsoft Office Excel Copyright © 2008 Prentice-Hall. All rights.
2.3 Organising Data for Effective Retrieval
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Chapter 3 Single-Table Queries
Microsoft Access 2010 Chapter 7 Using SQL. Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple.
MongoDB An introduction. What is MongoDB? The name Mongo is derived from Humongous To say that MongoDB can handle a humongous amount of data Document.
Objectives Overview Define the term, database, and explain how a database interacts with data and information Define the term, data integrity, and describe.
24 GOLDEN COINS, 1 IS FAKE ( WEIGHS LESS). DATABASE CONCEPTS Ahmad, Mohammad J. CS 101.
Database. Basic Definitions Database: A collection of related data. Database Management System (DBMS): A software package/ system to facilitate the creation.
Banner and the SQL Select Statement: Part Four (Multiple Connected Select Statements) Mark Holliday Department of Mathematics and Computer Science Western.
1 CS 430 Database Theory Winter 2005 Lecture 12: SQL DML - SELECT.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
CS 101 – Access notes Databases (Microsoft Access) 4 parts of a database database design –Try to understand the ideas behind database design, not just.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Database control Introduction. The Database control is a tool that used by the database administrator to control the database. To enter to Database control.
EAK 362/2 MIS LECTURE 4 PART 2 Managing Databases.
M1G Introduction to Database Development 5. Doing more with queries.
Part II. Query Types On the design query table pane, right click and the cascading window will appear.
SQL Basics. What is SQL? SQL stands for Structured Query Language. SQL lets you access and manipulate databases.
1. When things go wrong: how to find SQL error Sveta Smirnova Principle Technical Support Engineer, Oracle.
I want to do SQL, I start as if I am doing a regular query.
When I want to work with SQL, I start off as if I am doing a regular query.
1 Querying a Single Table Structured Query Language (SQL) - Part II.
Queries SELECT [DISTINCT] FROM ( { }| ),... [WHERE ] [GROUP BY [HAVING ]] [ORDER BY [ ],...]
Using SQL Connecting, Retrieving Data, Executing SQL Commands, … Svetlin Nakov Technical Trainer Software University
Chapter 13 Views Oracle 10g: SQL. Oracle 10g: SQL2 Objectives Create a view, using CREATE VIEW command or the CREATE OR REPLACE VIEW command Employ the.
Databases 101 © Dolinski What you will learn How relational databases work What are the components that make up a database How to create each component.
ITEC 3220A Using and Designing Database Systems Instructor: Prof. Z. Yang Course Website: 3220a.htm
Announcements Written Homework 1 due Nov 2 –See course web page –Exercises 5.12, 5.15, 6.17, 6.20, 6.22 (a,c,f only). Today –continue with SQL (chapter.
9-1 © Prentice Hall, 2007 Topic 9: Physical Database Design Object-Oriented Systems Analysis and Design Joey F. George, Dinesh Batra, Joseph S. Valacich,
CS 101 – Nov. 11 Finish Database concepts –1-1 relationship –1-many relationship –Many-to-many relationship Review.
CS 111 – Nov. 8 Databases Database Management Systems (DBMS) Structured Query Language (SQL) Commitment –Please review sections 9.1 – 9.2.
Structured Query Language SQL Unit 4 Solving Problems with SQL.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Lecture Access – Queries. What’s a Query? A question you ask a database –ie: “Who are my Stockton customers?” –ie: “How much did Bob sell on the 14th?”
Agenda for Class - 03/04/2014 Answer questions about HW#5 and HW#6 Review query syntax. Discuss group functions and summary output with the GROUP BY statement.
MIS2502: Data Analytics SQL – Getting Information Out of a Database.
Lab 1 Writing Interactive Queries CISB514 Advanced Database Systems.
Fall Lab 131 CS105 Lab 13 – Logical Operator Precedence and Joining Tables Announcements: MP 3 released Friday, 11/20 Honors project due: Tuesday,
1 A Very Brief Introduction to Relational Databases.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
Tarik Booker CS 122. What we will cover… Tables (review) SELECT statement DISTINCT, Calculated Columns FROM Single tables (for now…) WHERE Date clauses,
IFS180 Intro. to Data Management Chapter 10 - Unions.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Chapter 5 Introduction to SQL.
SQL Relational Database Project
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
ATS Application Programming: Java Programming
Current outstanding balance
PROC SQL, Overview.
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Aggregating Data Using Group Functions
SQL LANGUAGE and Relational Data Model TUTORIAL
Prof: Dr. Shu-Ching Chen TA: Haiman Tian
Access: SQL Participation Project
Databases Continued 10/18/05.
Topic - DML - Select statement
Presentation transcript:

CS 111 – Nov. 10 Structured Query Language (SQL) –We’ve already seen simple select statements, with optional “where” clause and aggregate functions. –More example commands today Relational database Commitment –Review for test after lab

Log in As you will see in lab, you first need to “log in” to the database management system in order to see your database. From a Web browser, go to cs.furman.edu/phpMyAdmin/ Enter your database username & password (Demo) If your SQL commands are incorrect, you’ll get error message.

Example FirstLastLocationTitleSalary PeterJacobsBrusselsBroker55000 DeniseLambertBrusselsAccountant42500 RobertNijsBrusselsBroker66700 RuthMolloyChicagoManager68650 DeclanMurphyChicagoAccountant84125 SusanPattersonChicagoEconomist51000 RachelBradyCincinnatiBroker43300 DavidCunninghamCincinnatiAccountant48000 JohnWhelanCincinnatiBroker60500 YvonneButlerSan DiegoBroker48500 VeronicaKeatingSan DiegoBroker72000 MaryWalshDublinAccountant46850 An abridged Employee table:

Distinct Sometimes in SQL you have a lot of repeated data. And you only want the values themselves, not the repetitions. –Ex. 70, 70, 70, 80, 80, 80, 80, 80, 100  70, 80, 100 Examples select Test2 from Student; gives all test grades select distinct Test2 from Student; only shows each value once select distinct Test1, Test2 from Student; finds distinct pairs. 70/60, 70/80, and 90/80 are considered distinct.

Group by The “group by” clause is good at finding subtotals. Example: how many employees by job title: –Select count(first) from Employee group by Title; –Actually, doesn’t matter which field we count. To make output easier to understand, we should also print out the job titles: –Select Title, count(Salary), avg(Salary) from Employee group by title; We can even subtotal by 2 fields: What would this command mean? –Select Location, Title, count(Salary) from Employee group by Location, Title;

Order by This clause is used for sorting. Default order is ascending. select * from Employee order by Last; select * from Employee order by Location, Last; select * from Employee where Salary > order by Location, Title;

More on “where” Boolean conditions: when you use the “where” clause can include the word “and” or “or” to make complex conditions. –Ex. What if we wanted salaries of employees with names starting with M or P. Use “in” when you want to select among several possible values. Has the same effect as “or” –Select * from Employee where Location in (“Dublin”, “Chicago”); Use “between” for an (inclusive) range of values to check –Select * from Employee where Salary between and 70000;

Relational Database Databases with just 1 table are not very powerful. More interesting if 2 tables are related. –Books and publishers –Customers and orders –Pets and owners Typically we have a “one-to-many” relationship The two tables need to have a field in common. –You can see this if you try to list the necessary fields in the above examples. In SQL, to refer to a field within some table, we use the dot notation: Customer.First, Pet.Name, Order.ID