i want to do sql, i start as if i am doing a regular query

36
I want to do SQL, I start as if I am doing a regular query.

Upload: emmeline-white

Post on 14-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: I want to do SQL, I start as if I am doing a regular query

I want to do SQL, Istart as if I am doinga regular query.

Page 2: I want to do SQL, I start as if I am doing a regular query

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 and I select SQL. It brought up SELECTFROM books;I wanted to see all fields, so I put in the * so I am now selecting all fields from the table books.

Page 3: I want to do SQL, I start as if I am doing a regular query
Page 4: I want to do SQL, I start as if I am doing a regular query

Now I just want to see specific fields. I am going to change the * and list the fields that I want to see.I coded it in a separate word document to get a better size to show the class. I am going to copy and paste over to the Query3 that now contains SELECT * FROM books;Please note the semi-colon at the end of the SQL command.

Page 5: I want to do SQL, I start as if I am doing a regular query

Now I have the SQL in query 3. To execute I click on the icon to display the results.

Page 6: I want to do SQL, I start as if I am doing a regular query

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.

Page 7: I want to do SQL, I start as if I am doing a regular query

I corrected and put the accurate field name of yearPub.

Page 8: I want to do SQL, I start as if I am doing a regular query
Page 9: I want to do SQL, I start as if I am doing a regular query

This is WRONG. The order of the clauses is important. The FROM clause should be on the second line and the WHERE clause on the third line.

Page 10: I want to do SQL, I start as if I am doing a regular query

It is now corrected.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 the class can see the code better.

This is Query3 thatI will run.

Page 11: I want to do SQL, I start as if I am doing a regular query

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.

Page 12: I want to do SQL, I start as if I am doing a regular query

It is important when I compare fields to have the 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 ABC was the name of a field.Numerics are not put in quotes if they are being compared to a numeric field.

Page 13: I want to do SQL, I start as if I am doing a regular query

I amde some changes in the structure and made edition a numeric field, I believe it was text.

Page 14: I want to do SQL, I start as if I am doing a regular query

Now I am checking two things in an AND relationship.The second thing is comparing edition (which I made numeric) to 2. A numeric to numeric test.

Page 15: I want to do SQL, I start as if I am doing a regular query

Text fields are pushed against the left wall and numeric fields are pushed against the right wall.

Page 16: I want to do SQL, I start as if I am doing a regular query

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 needed.

Page 17: I want to do SQL, I start as if I am doing a regular query
Page 18: I want to do SQL, I start as if I am doing a regular query
Page 19: I want to do SQL, I start as if I am doing a regular query

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 on 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.

Page 20: I want to do SQL, I start as if I am doing a regular query
Page 21: I want to do SQL, I start as if I am doing a regular query

I changed the AND to an OR so I get records that either have ABC or have edition 2.

Page 22: I want to do SQL, I start as if I am doing a regular query

This is an OR relationship.

Page 23: I want to do SQL, I start as if I am doing a regular query

Now I want to do this problem - see the next few pages.

Page 24: I want to do SQL, I start as if I am doing a regular query

This is not what I wanted. It reads publisher ABC and edition 2 OR just yearPub > 2003.

Page 25: I want to do SQL, I start as if I am doing a regular query

When I put in the parenthesis it resolves correctly.This reads publisher ABC AND either edition 2 OR yearPub > 2003.

Page 26: I want to do SQL, I start as if I am doing a regular query
Page 27: I want to do SQL, I start as if I am doing a regular query
Page 28: I want to do SQL, I start as if I am doing a regular query
Page 29: I want to do SQL, I start as if I am doing a regular query
Page 30: I want to do SQL, I start as if I am doing a regular query

This is how the SQL shows up on the quey user interface. Note that ABC is repeated because it has to be true.

Page 31: I want to do SQL, I start as if I am doing a regular query

This is the way that it is generated by Access.

Page 32: I want to do SQL, I start as if I am doing a regular query

This does not have the parenthesis so it will not solve my problem - it will resolve incorrectly.

Page 33: I want to do SQL, I start as if I am doing a regular query
Page 34: I want to do SQL, I start as if I am doing a regular query

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 a previous slide.

Page 35: I want to do SQL, I start as if I am doing a regular query

This shows the wrong code in the user interface.

Page 36: I want to do SQL, I start as if I am doing a regular query

When I want to copy a database, I go into windowsexplorer and drag it to another drive.This mdb is also what I wouldattach to an email.