Queries and SQL in Access

Slides:



Advertisements
Similar presentations
Structured Query Language (SQL)
Advertisements

Databases Section 4: Select Queries Presented By: Lindani Ncube Based on Materials by: M Halse.
1 Query-by-Example (QBE). 2 v A “GUI” for expressing queries. –Based on the Domain Relational Calulus (DRC)! –Actually invented before GUIs. –Very convenient.
Concepts of Database Management Seventh Edition
Instructor: Craig Duckett CASE, ORDER BY, GROUP BY, HAVING, Subqueries
Queries and SQL in Access Please use speaker notes for additional information!
CORE 2: Information systems and Databases STORAGE & RETRIEVAL 2 : SEARCHING, SELECTING & SORTING.
SQL Operations Aggregate Functions Having Clause Database Access Layer A2 Teacher Up skilling LECTURE 5.
Sorting data and Other selection Techniques Ordering data results Allows us to view our data in a more meaningful way. Rather than just a list of raw.
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
1 Section 5 - Grouping Data u The GROUP BY clause allows the grouping of data u Aggregate functions are most often used with the GROUP BY clause u GROUP.
Chapter 2 Basic SQL SELECT Statements Oracle 10g: SQL.
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 4 BACKNEXTEND 4-1 LINKS TO OBJECTIVES Query Design Query Criteria Modify a Query Using OR.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Appendix C Overview of the QBE (Query-By-Example) Language.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Database Management Systems.  Database management system (DBMS)  Store large collections of data  Organize the data  Becomes a data storage system.
SQL and Conditions Speaker notes will provide additional information!
Database Applications – Microsoft Access Lesson 4 Working with Queries 36 Slides in Presentation.
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.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
DATA RETRIEVAL WITH SQL Goal: To issue a database query using the SELECT command.
Information Resource Engineering SQL3. Recap- SQL Rules and Conventions  Certain ‘keywords’ are ‘reserved’ and have special meaning in SQL e.g.: SELECT,
Databases.  A database is simply a collection of information stored in an orderly manner.  A database can be as simple as a birthday book, address book.
XP New Perspectives on Microsoft Access 2002 Tutorial 31 Microsoft Access 2002 Tutorial 3 – Querying a Database.
A table is a set of data elements (values) that is organized using a model of vertical columns (which are identified by their name) and horizontal rows.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
LINQ to DATABASE-2.  Creating the BooksDataContext  The code combines data from the three tables in the Books database and displays the relationships.
# 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.
A am going to create a table in design view. I am going to create a table in an Access database that contains information about the books that I have on.
Fall Lab 131 CS105 Lab 13 – Logical Operator Precedence and Joining Tables Announcements: MP 3 released Friday, 11/20 Honors project due: Tuesday,
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
Finish ing the logic flowc harts from week 3.. if invcd = “A” and (amtfst > 500 or amtsnd > 200) move “OKAY” to msg end if With the parenthesis, invcd.
Creating a database - I clicked on blank database and am saving it as books10.mdb. For more information see the practice example under week #1. I am going.
Data Please use speaker notes for additional information!
IFS180 Intro. to Data Management Chapter 10 - Unions.
The data in the table.. Starting a query. Two criteria in an AND relationship.
Session 1 Retrieving Data From a Single Table
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Microsoft Office Access 2010 Lab 3
MySQL Subquery Source: Dev.MySql.com
Connect to SQL Server and run select statements
Writing Basic SQL SELECT Statements
Prepared by : Moshira M. Ali CS490 Coordinator Arab Open University
Instructor: Craig Duckett Lecture 09: Tuesday, April 25th, 2017
This shows the user interface and the SQL Select for a situation with two criteria in an AND relationship.
LINQ to DATABASE-2.
Access Database for CIS17
Please use speaker notes for additional information!
INFO/CSE 100, Spring 2005 Fluency in Information Technology
Using the Set Operators
Microsoft Office Access 2003
Access and Condition Statements
Tutorial 3 – Querying a Database
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
Week 3. criteria must be true..
Using SQL with Access I am adding queries to the stu table in SecondDB.accdb – a database that I created in class. SQL stands for structured query language.
LINQ to DATABASE-2.
Access Database for CIT12
Please use speaker notes for additional information!
Done with SQL..
Introduction to Access
Section 4 - Sorting/Functions
Notes on SQL This slide show will introduce SQL using Access. It assumes only an introductory level of knowledge about Access.
Shelly Cashman: Microsoft Access 2016
Using SQL with Access I create a database named
I am now going to do queries in SQL
either of two other things (an OR relationship between them)
Presentation transcript:

Queries and SQL in Access This slide show will introduce SQL in Access.

Textbook.mdb This is the database that we are looking at. The database has one table called book.

Query - all fields, all rows This shows the results of a query showing all columns/fields for all rows/records. The SQL equivalent of this query is shown on the next slide.

The table name also appears in the FROM clause Query with SQL All columns/fields for all rows/records means that in this case all of the columns/fields are listed in the SELECT clause with their table name in front. The table name also appears in the FROM clause Note that SQL code end with a semi-colon. This shows a basic SELECT where columns/fields are listed in the SELECT and the table name is given in the FROM.

SQL versions In this version, the book.ISBN has been changed to ISBN - this has been applied to all columns/fields. The table name is only needed if two tables are being used and the column/field appears on both. When Access translates the query into SQL it creates a query that is more complex than required if you know SQL. On this slide, I have include two simplified SQL codings. In this version, the SELECT * means select all columns/fields. You only need to list the columns/fields by name if you want only specific ones to appear in the results.

The results are shown below. Query - AND This is an AND query asking for all books with a year published greater than 1998 AND a price > 40. The results are shown below. This shows the simple AND query and the results.

The FROM clause specifies the table name. SQL for AND query The SELECT statement is specifying certain fields/columns that should be shown. In this case the fields are ISBN, title, yrpub and price. As you can see the table name is shown in front of the column name in the format book.ISBN etc. When a query is developed, the SQL is automatically generated. The FROM clause specifies the table name. The WHERE clause gives the condition. In this case the condition is the yrpub > 1998 or price > 40.

1998 is in quotes because it was defined as a text field. SQL - AND The SELECT only lists the columns/fields by name because there is no chance of duplication with only one table being used. The WHERE is coded by simply using the column name, the comparison operator and the field being compared against. 1998 is in quotes because it was defined as a text field. 40 is not in quotes because it was defined as a number (currency) field. The simplified version eliminates all of the unneeded parenthesis around the fields. They are their for clarity in some sense of the word!

OR Query Note that the OR requires separate lines in the query. Yrpub must be greater than 1999 OR price must be greater than 40. Either one is sufficient.

SQL - OR Again I have eliminated the table name in the select because there is no chance for duplication and the multiple parenthesis in the WHERE. This is very similar to the AND query on the previous slides. The simple version is shown as well!

The table is shown in ascending order by ISBN. AND - OR The table is shown in ascending order by ISBN. The query wants books with price greater than 40 AND with a pubid of either 001 OR 002. This is a case where the price must be greater than 40 AND either the pubid is 001 or the pubid is 002. Note that when the condition is expressed in logical terms the OR has to be surrounded by parenthesis. price > 40 AND (pubid = 001 OR pubid = 002) The rule is ANDs are resolved before ORs. If there were no parenthesis then the two conditions around the AND would be treated as a unit and the condtion after the OR would stand alone.

Notice the ORDER BY ISBN clause which accomplishes the ascending sort. AND - OR Notice the ORDER BY ISBN clause which accomplishes the ascending sort. Logic: cond A AND either (cond B OR cond C) It should be notes that when I went back and looked at the query after these changes they were expressed differently. Price must be greater than 40 AND either pubid = 001 OR pubid = 002. Note the way the OR is expressed.