Chapter 10 - EQUALITY AND INEQUALITY PREDICATES MeaningPredicate Equal to= Not equal to<> Less than< Less than or equal to<= Greater than> Greater than.

Slides:



Advertisements
Similar presentations
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Advertisements

Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
1 SQL-Structured Query Language SQL is the most common language used for creating and querying relational databases. Many users can access a database applications.
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!)
Microsoft Access 2010 Chapter 7 Using SQL.
What do you know? In your own words briefly describe what you know about databases? – Where are they used? – What are they used for? – How do they look?
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Rationale Aspiring Database Developers should be able to efficiently query and maintain databases. This module will help students learn the Structured.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
CS&E 1111 AcQueries Writing Simple Queries in Access Displaying on specific data fields Filtering data using criteria Objectives: Learn how to use the.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
CS&E 1111 AcQueries Querying in Access Sorting data Aggregating Data Performing Calculations Objectives: Learn how to use the Access Query Design Tool.
SQL in Action Amit Bhawnani & Nimesh Shah. Basic Structure SQL is based on set and relational operations with certain modifications and enhancements A.
Microsoft Access Queries Birgül Kutlu. SORTING AND FILTERING Sorting and filtering allow you to view records in a table in different ways such as: reordering.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
Module 1: Introduction to Transact-SQL
Lecture6:Data Manipulation in SQL, Simple SQL queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture6 1.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Restricting and Sorting Data. ◦ Limiting rows with:  The WHERE clause  The comparison conditions using =,
2 Copyright © Oracle Corporation, All rights reserved. Restricting and Sorting Data.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
SQL (DDL & DML Commands)
1.NET Web Forms Business Forms © 2002 by Jerry Post.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
IMS 4212: Intro to SQL 1 Dr. Lawrence West, Management Dept., University of Central Florida Introduction to SQL—Topics Introduction to.
CN2180 MS SQL Server Kemtis Kunanuraksapong MSIS with Distinction, A+ MCTS, MCDST, MCP.
Order Entry Program Please see speaker notes for additional information!
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
INSERT Statement. 2 home back first prev next last What Will I Learn? Give examples of why it is important to be able to alter the data in a database.
Database Fundamentals Objective 5.01: Understand database tables used in business.
SQL SELECT Getting Data from the Database. Basic Format SELECT, FROM WHERE (=, >, LIKE, IN) ORDER BY ; SELECT LastName, FirstName, Phone, City FROM Customer.
Session 9 Accessing Data from a Database. RDBMS and Data Management/ Session 9/2 of 34 Session Objectives Describe the SELECT statement, its syntax and.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
# 1# 1 QueriesQueries How do we ask questions of the data? What is SELECT? What is FROM? What is WHERE? What is a calculated field? Spring 2010 CS105.
Microsoft Access Lesson 5 Lexington Technology Center February 25, 2003 Bob Herring On the Web at
Introduction to Database SEM I, AY Department of Information Technology Salalah College of Technology Chapter No.3 SQL.
Module 2: Querying and Filtering Data. Using the SELECT Statement Filtering Data Working with NULL Values Formatting Result Sets Performance Considerations.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
Select Statement IT 350. Select Statement SELECT statement is what we use to choose, or select, the data that we want returned from the database to our.
In-Class SQL Query Exercises For the Plumbing Supply Store Database.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
Tarik Booker CS 122. What we will cover… Tables (review) SELECT statement DISTINCT, Calculated Columns FROM Single tables (for now…) WHERE Date clauses,
1 Section 3 - Select Statement u The Select statement allows you to... –Display Data –Specify Selection Criteria –Sort Data –Group Data for reporting –Use.
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
Writing Simple Queries in Access
Order Database – ER Diagram
How to: SQL By: Sam Loch.
CHAPTER 7 DATABASE ACCESS THROUGH WEB
SQL Query Getting to the data ……..
Prepared By: Bobby Wan Microsoft Access Prepared By: Bobby Wan
Order Database – ER Diagram
Querying in Access Objectives: Learn how to use the Access Query Design Tool manipulate data in Access: Sorting data Aggregating Data Performing Calculations.
Writing Basic SQL SELECT Statements
Order Database – ER Diagram
MIS5101: Business Intelligence Relational Data Modeling
02 | Querying Tables with SELECT
Web Services שפת SQL כתבה: זהבה יעקובסון ליווי מקצועי : ארז קלר
MIS2502: Data Analytics Converting ERDs to Schemas
Introduction To Structured Query Language (SQL)
Order Database – ER Diagram
Introduction To Structured Query Language (SQL)
ER Diagram Master How to use this template
MIS2502: Data Analytics Relational Data Modeling 3
02 | Querying Tables with SELECT
Presentation transcript:

Chapter 10 - EQUALITY AND INEQUALITY PREDICATES MeaningPredicate Equal to= Not equal to<> Less than< Less than or equal to<= Greater than> Greater than or equal to=> Business TaskTechnical Solution Find a customer based on the exact entry of his/her last name. SELECT * FROM Customers WHERE (lastname = "Delaney") Find orders for which the shipping cost was more than $35. SELECT OrderID, OrderDate, ShippedDate, ShippingCost FROM Orders WHERE ShippingCost > 35 ORDER BY ShippingCost DESC Select all orders with an order date later than June SELECT OrderID, OrderDate, ShippedDate, ShippingCost FROM Orders WHERE OrderDate > #6/30/2012# ORDER BY OrderDate

Chapter 11 - BETWEEN OPERATOR The BETWEEN AND OPERATOR is used to retrieve a set of data within two boundaries (usually dates or numbers). The BETWEEN AND operator is inclusive, that is the boundaries will be included in the result set. Business TaskTechnical Solution Find products in our inventory with prices between $15 and $18. SELECT productname, productunitprice FROM products WHERE productunitprice BETWEEN 15 AND 18 ORDER BY productunitprice Find orders placed within a date range.SELECT OrderID, orderdate, shippeddate FROM orders WHERE orderdate BETWEEN #6/15/2012# AND #8/15/2013# ORDER BY orderdate DESC Find orders placed within a range of years.SELECT OrderID, orderdate, shippeddate FROM orders WHERE year(orderdate) BETWEEN 2013 AND 2014 ORDER BY orderdate DESC

Chapter 12 - IN OPERATOR Business TaskTechnical Solution Create a report of customers from multiple cities SELECT lastname, firstname, city FROM customers WHERE city in ('New York', 'Boston', 'Chicago', 'Los Angeles', 'Dallas') Create a report of products based on specific prices SELECT productname, quantityperunit, productunitprice FROM products WHERE productunitprice in (15, 19, 22, 23, 42) Generate a report of orders in which there is at least one non-discounted product SELECT orderid, orderdate, shippeddate FROM orders WHERE orderid IN (SELECT orderid FROM ProductsOrders WHERE (Discount) =0) The primary role of the IN operator is to participate in search conditions for filtering records It takes the place of multiple OR operators. It is indispensable with subqueries

Chapter 13 - DISTINCT PREDICATE The DISTINCT predicate is used to eliminate duplicate rows from the results of a SELECT statement. It belongs to a set of four predicates (ALL, TOP, DISTINCT, DISTINCTROW) Business TaskTechnical Solution Find all cities in which we have customers Distinct on one column SELECT city FROM customers SELECT DISTINCT city FROM customers Finding unique customer names in various states Distinct with multiple columns If we include the DISTINCT clause such as: SELECT DISTINCT firstname, state FROM customers Complete the first four examples only

Chapter 14 – The TOP PREDICATE The top predicate by itself does not produce useful results. We can use it with the order by clause however for useful information. Business TaskTechnical Solution Top with numbers – Look for the five products with most units in stock SELECT TOP 5 productname, unitsinstock, unitsonorder FROM Products ORDER BY unitsinstock DESC Top with dates - Look for the five more recently hired employees SELECT TOP 5 lastname, firstname, DateofHire FROM SalesReps ORDER BY DateofHire DESC Get the ten largest orders for a particular product SELECT TOP 10 orderid, productid, (unitprice*quantity) AS orderamount FROM ProductsOrders WHERE (productid=2) ORDER BY (unitprice*quantity) DESC;

Chapter 15 – Calculated Fields Calculated fields are temporary columns created using arithmetic operators such as (+, *, -, /, ^) Are used extensively for short term or permanent changes with update statements. For example, a temporary price increase or cut in our web based product catalog. Business TaskTechnical Solution Create a product catalog with updated prices on the fly SELECT productname, productunitprice + 5 AS productprice FROM Products Calculate product inventory quantitiesSELECT productname, unitsinstock, unitsonorder, (unitsinstock + unitsonorder) AS TotalUnits FROM products Provide customers with different discounts based on the product supplier SELECT productname, SWITCH( SupplierID = 1, ProductUnitPrice*(1-0.2), SupplierID = 2, ProductUnitPrice*(1-0.15), SupplierID = 3, ProductUnitPrice*(1-0.18), SupplierID = 4, ProductUnitPrice*(1-0.25), TRUE, ProductUnitPrice*(1-0.1) ) AS ProductPrice FROM Products

Chapter 16 – Concatenated Fields Concatenating columns means nothing more than displaying the contents of two or more columns in one. To concatenate fields in MS Access 2010, we can use the "&" character or the "+" character. Business TaskTechnical Solution Put all customer address information in one field with spaces between values SELECT (address +' '+ city +' '+ state +' '+ zip) AS FullAddress FROM Customers Write a customer letterSELECT "Dear" + ' '+ (lastname + ' ' + firstname) +"." + ' '+ "It is our pleasure to announce that we reviewed your resume, and we have set up an interview time for you. Can you please verify that your address is" + ' ' + (address +' '+ City +' '+ State +' '+ Zip) + ' ' + "to send you corporate policy details and directions?" AS CustomerLetter FROM Customers