1 / 15

Notes on SQL

Notes on SQL. Please use speaker notes for additional information!. 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.

landon
Télécharger la présentation

Notes on SQL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Notes on SQL Please use speaker notes for additional information!

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

  3. SELECT * means to select all fields so we see all fields from all records in the table tablestu.

  4. The code: SELECT idno, name, major, gpa, credits FROM tablestu; means that only the named fields will be part of the query.

  5. SELECT idno, name, gpa, credits, major FROM tablestu;

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

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

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

  9. 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 Processed when Ques1 OR Ques2 must be true Not processed when Ques 1 OR Ques 2 must be true

  10. 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. All records have CI as their major since this is a requirement in our criteria.

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

More Related