Notes on SQL This slide show will introduce SQL using Access. It assumes only an introductory level of knowledge about Access.

Slides:



Advertisements
Similar presentations
Some Introductory Programming 1. Structured Query Language (SQL) - used for queries. - a standard database product. 2. Visual Basic for Applications -
Advertisements

Queries and SQL in Access Please use speaker notes for additional information!
SQL and Conditions Speaker notes will provide additional information!
1 Database Systems Introduction to Microsoft Access Part 2.
Introduction to Access 2010 CIS120first.accdb is the database I am creating.
Database Applications – Microsoft Access Lesson 4 Working with Queries 36 Slides in Presentation.
1 Chapter 3: Customize, Analyze, and Summarize Query Data Exploring Microsoft Office Access 2007.
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.
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.
ACCESS 3. OBJECTIVES Calculated fields in query design Total option in query design Creating Forms.
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.
Sample template for portfolio - I would prefer to see you do something more original!
Computer Science Up Down Controls, Decisions and Random Numbers.
The data in the table.. Starting a query. Two criteria in an AND relationship.
Retrieving Data Using the SQL SELECT Statement
Microsoft Office Access 2010 Lab 3
Prof. Mark Glauser Created by: David Marr
Microsoft Access 2013 Bobby Wan.
Microsoft Office Illustrated Introductory, Windows Vista Edition
This shows the user interface and the SQL Select for a situation with two criteria in an AND relationship.
On new..
Single Table Queries in SQL
Access Database for CIS17
MySQL - Creating donorof database offline
Please see speaker notes for additional information!
Please use speaker notes for additional information!
Microsoft Office Access 2003
IDENTIFIERS CSC 111.
Making Decisions in a Program
Access and Condition Statements
Generating forms with the wizard in Access
Conditions and Ifs BIS1523 – Lecture 8.
Tutorial 3 – Querying a Database
Graphical Interface for Queries
Please use speaker notes for additional information!
follow this structure. Creating records following the structure of the table is populating the table.
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
Using Access 2016 Since we are creating a new Access database, we need to select blank database.
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.
Microsoft Office Access 2003
Miscrosoft Office..
I am opeing Access 2003 in the Microsoft Office.
Introduction to Views and Reports
You can read it better when I make the change.
These are user interface queries
On new..
Access Database for CIT12
In this case I should have had a " after OKAY as well In this case I should have had a " after OKAY as well. I can also move OKAY by assigning.
We are starting JavaScript. Here are a set of examples
Searching an Array or Table
Microsoft Visual Basic 2005: Reloaded Second Edition
Lab 2 and Merging Data (with SQL)
Environment/Report Tutorial
Please use speaker notes for additional information!
Done with SQL..
This is the example I want the class to put up to become comfortable with creating and populating a table in Access.
Using screens and adding two numbers - addda.cbl
Introduction to Access 2010
Using Access to generate a report
Queries and SQL in Access
Microsoft Office Illustrated Introductory, Windows XP Edition
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)
Template for the portfolio.
Access Click on file and then you want a new database.
Presentation transcript:

Notes on SQL This slide show will introduce SQL using Access. It assumes only an introductory level of knowledge about Access.

This is the database that I am using to do my queries.

First I choose doing a query in design view the way I do when I am creating other queries. Now I am going to select the table which is tablestu to do the query. I do this by clicking on Add and then clicking on Close since I am only using 1 table.

I have now selected the table, I click on the down arrow beside the Datasheet View icon to review SQL View. This is what I am going to select.

The table I selected is tablestu so it knows that I am going to SELECT information FROM tablestu. Note that the semi-colon ends SQL statements. Since I did not select any fields when I was in the query interface, just a table, this is what appears in the SQL Query window. Now I have to make changes to tell it what to SELECT.

SELECT * means to select all fields so we see all fields from all records in the table tablestu. In SQL, you can select all of the fields from the database records by using an * or you can choose individual fields by naming them. The named elements will be separated by a comma as shown on the next slide.

SELECT idno, name, major, gpa, credits FROM tablestu; The code: SELECT idno, name, major, gpa, credits FROM tablestu; means that only the named fields will be part of the query. Naming fields in the SELECT statement is the same as clicking on them or otherwise bringing them down to the query. You do not have to bring down all of the fields to make the query work. Note that the fields appear on the output in the order that they are named in the SELECT.

SELECT idno, name, gpa, credits, major FROM tablestu; Notice that I said I wanted the order to be idno, name, gpa, credits and major in my SELECT and this is the order that I see the data in my output.

SELECT idno, name, major FROM tablestu WHERE major = “CI”; WHERE lets me select specific records. In this example, I want to select the records where the major field contains CI. Note that the output only has the records where the major = “CI” which means that only 7 of the original 14 records are shown. The where clause allows me to put conditions on the select. In this example I only want records that meet the condition or criteria of major = "CI". CI must be enclosed in quotes because it is a literal using characters or text. If it was not enclosed in quotes it would be unclear whether this was a variable name or a literal. Note that the commands can be in either upper or lower case. In this example, the where was coded in lower case. I prefer the uppercase, because they stand out, but programming conventions seem to be leaning toward lowercase.

In this example, I am comparing gpa which is a numeric field against the number 3. The 3 is not in quotes because it is a literal and a number. Non-numeric literals must be in quotes, but numeric literals should not be in quotes. This query is showing the idno, name, major and gpa for all students with a gpa > 3. Note that I could also have used a decimal, for example gpa > 3.5.

This shows a compound AND where I want major = "CI" and gpa > 3. 25 This shows a compound AND where I want major = "CI" and gpa > 3.25. Note that this is a typical AND where both components of the condition have to be true.

This first line got displayed because the major = “CI” This first line got displayed because the major = “CI”. Since the gpa is not > 3.25 it would not have been displayed if both criteria had to be true. The third line got displayed because gpa > 3.25. Since the major is BU, it would not have been displayed if both criteria had to be true. This is a classic OR where one or the other of the criteria has to be true to be displayed. Either one can be true. For that matter both can be true, but that is not what we are testing for. We are testing to see if either one is true.

Y Y Processed when Ques 1 AND Ques 2 must both be true Y N N Y N N In the AND SELECT and the OR SELECT on the previous slide, we had two questions. When you have 2 questions, there are four possible outcomes and they are handled differently depending on whether there is an AND condition or an OR condition. AND: Ques 1 Ques 2 Y Y Processed when Ques 1 AND Ques 2 must both be true Y N N Y N N Not processed when Ques 1 AND Ques 2 must both be true OR: Ques 1 Ques 2 Y Y Y N N Y N N This shows the relationship of 2 questions when looked at when the conditions are in an AND relationship and when looked at when the conditions are in an OR relationship. Processed when Ques1 OR Ques2 must be true Not processed when Ques 1 OR Ques 2 must be true

Record 2 does not meet the gpa requirement but it does meet the credits requirement. Since one or the other had to be true, it is showing. Record 3 does not meet the credits requirement but it does meet the gpa requirement. Since one or the other had to be true, it is showing. In this condition, the major has to be CI and then either of the other two criteria must be true. Remember that in logic AND gets resolved before OR. This would mean that major = "CI" and gpa > 3.25 would be grouped together and credits > 40 would stand alone. This is not what we want. We can use parenthesis to change the order. By grouping the two conditions in the or relationship with the parenthesis, we end up with major = "CI" and EITHER gpa > 3.25 OR credits > 40 which is exactly what we want. All records have CI as their major since this is a requirement in our criteria.

Record 1 has credits of 15 which means it is less than 20. Record 2 has credits of 45 which means it is greater than 40 Record 5 is outside the range of 20 to 40 because 3 is less than 20. In this example I want major = “CI” and credits outside a certain range. I do not want CI majors with credits in the range of 20 to 40. I want CI majors below the minimum of 20 and above the maximum of 40.