Download presentation
Presentation is loading. Please wait.
Published byAmberly Annabel Gilbert Modified over 9 years ago
1
When I want to work with SQL, I start off as if I am doing a regular query.
2
When I get to the user interface, I add the table and then I go to the icon that lets me look at how to view what I did. From there, I select SQL. In this example, it brought up SELECT FROM books; I wanted to see all fields, so I put in the * after SELECT. Therefore, I am selecting all fields from the table named books.
4
Now, I want to see specific fields. I am going to change the * and list the fields that I want to see. Note: What your seeing displayed on top of the Access view is a separate Notepad file that was resized to make it easier for you to see the SQL statement. I am going to copy and paste over the query that now says SELECT * FROM books; Please note the semi-colon at the end of the SQL command.
5
My final SQL SELECT statement has been changed to: SELECT ISBN, title, publisher Note that this is still searching within the “books” table. To execute this, I must click on the icon to display the results.
6
If I put a field that does not exist in the field list, I get this response. There is no field called yr on the table.
7
I have now corrected it and replaced yr with the accurate field name of yearPub.
9
This is WRONG. The order of the clauses are important! The FROM clause should be on the second line and the WHERE clause should be on the third line.
10
Now, it is correct! Please note again that there is a semi-colon only after all of the clauses. Also remember, this is just a copy in notepad so you can see the code better. This is Query3 that I will run.
11
I showed the result and I showed the separate copy in notepad since I cannot show the query code and the result at the same time. Again, this is just a copy in notepad.
12
It is important that when I compare fields, I reference fields of the same type. I put the ABC in quotes because it is a text/string field and therefore must be enclosed in quotes. If I did not use quotes, it would assume that ABC was the name of a field. Numerical data should not be surrounded by quotes if it is being compared to a numeric field.
13
I made some changes in the structure and added an “Edition” filed.
14
Here I am checking two things using an AND relationship. The second thing is comparing “edition” (which I made numeric) to “2”, which is testing a numeric to a numeric reference.
15
The text fields are pushed against the left wall and the numeric fields are pushed against the right wall.
16
This shows the SQL and the user interface. Please note that sometimes when you bring up the user interface it changes the code in the SQL by putting in a lot of parenthesis, etc. that are not necessary.
19
This shows the SQL generated by Access. This is NOT the way I want you to write it. Note that books.ISBN means the ISBN field within the books table, but since I am only using one table, these are not necessary. Also note the parenthesis, none of which are needed in this example.
21
I changed the AND to an OR so I get records that either have ABC or have edition 2.
22
This is an OR relationship.
23
Now I want to do this problem - see the next few pages.
24
This is not what I wanted. It reads publisher ABC and edition 2 OR just yearPub > 2003.
25
When I put it within parenthesis, it renders correctly. This reads publisher ABC AND either edition 2 OR yearPub > 2003.
30
This is how the SQL shows up on the query user interface. Note that ABC is repeated because it has to be true.
31
This is the way that it is generated by Access.
32
This does not have the parenthesis so it will not solve my problem - it will render incorrectly.
34
This shows the fact that I get the wrong output - one of the records has CDE. Note that I went back and changed the data for better results. See list of data on one of the previous slides.
35
This shows the wrong code in the user interface.
36
When I want to copy a database, I go into windows explorer and drag it to another drive. This mdb is also what I would attach to an email for submission. Please keep in mind that the 2007 version of Access uses a different filename extension.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.