1 / 14

Mastering SQL: Essential SELECT Queries and Filters

This guide covers the fundamentals of SQL SELECT statements, detailing syntax and usage to extract data from tables effectively. Learn how to implement WHERE clauses to filter results, using AND/OR conditions for refined queries. Discover the ORDER BY clause to sort your data in ascending or descending order, and how to create column aliases for clarity in results. We'll explore the LIKE operator for pattern matching in queries. With practical examples based on a Playoffs table, this resource is ideal for both beginners and those looking to enhance their SQL skills.

ziva
Télécharger la présentation

Mastering SQL: Essential SELECT Queries and Filters

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. Quick SQL practice • Table Name:Playoffs • Fields • Player IDText (3 characters); key field • MinutesNumber • FTMNumber • FTANumber • ReboundsNumber • StealsNumber • BlocksNumber • Total PointsNumber

  2. More SQL SELECT

  3. Extracting Data from Tables • The SELECT statement • Probably the single most important and widely used SQL command • Syntax: SELECTfields FROMtable WHEREcondition;

  4. A simple SELECT query SELECT Lastname FROM STAR;

  5. More Fields SELECT Lastname, Firstname FROM STAR;

  6. All fields SELECT * FROM STAR;

  7. The WHERE clause • The WHERE clause is the mechanism for filtering out unwanted rows from your results table SELECT Lastname FROM STAR WHERE Lastname=‘Moore’;

  8. AND andOR • More than one condition SELECT Lastname, Firstname FROM Customer WHERE Lastname='Brown' AND Age>20;

  9. OR SELECT Lastname, Firstname FROM customer WHERE Lastname='Brown' OR Age>20; What’s the difference in the results?

  10. A little more nuanced SELECT Lastname, Firstname FROM customer WHERE (Lastname='Brown' AND State='CA') OR (Age>20 AND Sex='F');

  11. ORDER BY • We can sort the results in either ascending or descending order • The default is ascending order. SELECT Lastname, Firstname FROM customer WHERE (Lastname='Brown' AND State='CA') OR (Age>20 AND Sex='F') ORDER BY Firstname;

  12. ORDER BY in descending order SELECT Lastname, Firstname FROM customer WHERE (Lastname='Brown' AND State='CA') OR (Age>20 AND Sex='F') ORDER BY Firstname DESC;

  13. Creating column aliases SELECT LastnameASLName, Firstname FROM customer WHERE (Lastname='Brown' AND State='CA') OR (Age>20 AND Sex='F') ORDER BY Firstname DESC;

  14. LIKE SELECT Lastname FROM customer WHERE Lastname LIKE "B*“;

More Related