SlideServe
Menu
Préférences
© SlideServe · v2026

SQL Data Retrieval Basics

kirestin-pollard avatar
13 diapositives · 227 Views · Oct 25, 2014

Learn the fundamentals of SQL SELECT queries to extract data from a database. Understand syntax for specifying fields, tables, criteria, sorting, aliases, calculations, and handling NULL values.

SQL Data Retrieval Basics - slide 1
01 / 13SQL Data Retrieval Basics
1 / 17

Télécharger la présentation

SQL Data Retrieval Basics
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. SQL SELECT Getting Data from the Database

  2. Basic Format SELECT <fieldname>,<fieldname> FROM <tablename> WHERE <fieldname> (=, >, < , <> LIKE, IN) <some criteria> ORDER BY <fieldname>; SELECT LastName, FirstName, Phone, City FROM Customer WHERE City=‘Seattle’ ORDER BY LastName;

  3. Key Words • SELECT –every query that returns data starts with SELECT • FROM –determines what table(s) • WHERE –sets up the Criteria • ORDER BY –sorts by the field(s) listed Note: SELECT * FROM Customer, the * means select all columns

  4. AS, Aliasing • The names of the columns may not always be the names you wish to use in a query result. You can use the AS keyword to alias it for the result SELECT LastName AS “Last Name”, FirstName AS “First Name” FROM Customer;

  5. Calculated Fields SELECT 5 * 3 / 2; SELECT lastname + ‘, ‘ firstname AS “Customer Name”, Phone FROM Customer; SELECT OrderID, (ItemPrice * Quantity) AS “SubTotal” FROM OrderDetail WHERE OrderID=1223;

  6. ORDER BY • ORDER BY sorts by the selected field in an Ascending order by default. • You can add the DESC keyword to change the sort order to Descending • If you have multiple fields the leftmost is the primary sort, the next leftmost is the secondary sort etc. SELECT LastName, FirstName, City, phone FROM Customer ORDER BY City, LastName DESC; Note: the DESC only applies to the LastName field

  7. WHERE CRITERIA • You can use all the basic comparative operators

  8. Criteria • Number values are used without quotes • Character (text) values are quoted with single ‘’ quotes • Dates are quoted with single quotes except in Access where they put between pound # signs

  9. Between • You can use the BETWEEN keyword to look for values “between” to limiting values. • The Between includes the ends SELECT OrderID, OrderDate FROM Order WHERE OrderDate BETWEEN #1/1/2007# AND #1/31/2007#;

  10. AND OR NOT • SELECT * • FROM Customer • WHERE State = ‘WA’ • AND City = “Seattle” • OR City = “Tacoma” • AND NOT City = “Bellevue”

  11. LIKE • With the keyword LIKE in conjunction with wildcards will let you search for patterns in text fields • The wild cards are • % any string of characters • _ any one character

  12. LIKE Examples SELECT * FROM Customer WHERE LastName LIKE ‘Ch%’; SELECT * FROM Course WHERE CourseName LIKE ‘MIC12_’

  13. Nulls • You can search for Nulls with the key words IS NULL • SELECT SectionNumber, StudentID, QuarterGrade • FROM Section • WHERE SectionID=‘2830’ • AND QuarterGrade IS NULL