Back to 课程

Computer Science GCES AQA

0% Complete
0/0 Steps
  1. Representing Algorithms Aqa
    4 主题
  2. Efficiency Of Algorithms Aqa
    1 主题
  3. Searching Algorithms Aqa
    3 主题
  4. Sorting Algorithms Aqa
    3 主题
  5. Data Types Aqa
    1 主题
  6. Programming Concepts Aqa
    5 主题
  7. Arithmetic Relational And Boolean Operations Aqa
    1 主题
  8. Data Structures Aqa
    3 主题
  9. String Manipulation Aqa
    1 主题
  10. Random Number Generation Aqa
    1 主题
  11. Structured Programming Aqa
    2 主题
  12. Robust And Secure Programming Aqa
    4 主题
  13. Number Bases Aqa
    2 主题
  14. Converting Between Number Bases Aqa
    3 主题
  15. Units Of Information Aqa
    9 主题
  16. Hardware And Software Aqa
    4 主题
  17. Boolean Logic Aqa
    3 主题
  18. Programming Languages And Translators Aqa
    2 主题
  19. Cpu Architecture Performance And Embedded Systems Aqa
    4 主题
  20. Memory Aqa
    2 主题
  21. Secondary Storage Aqa
    3 主题
  22. Fundamentals Of Computer Networks Aqa
    8 主题
  23. Fundamentals Of Cyber Security Aqa
    1 主题
  24. Methods Of Preventing Cyber Security Threats Aqa
    1 主题
  25. Relational Databases Aqa
    2 主题
  26. Ethical Legal And Environmental Impacts Aqa
    2 主题
课 Progress
0% Complete

Exam code:8525

Retrieving Data Using SQL

What is SQL?

  • SQL (Structured Query Language) is a programming language used to interact with a DBMS.

  • The use of SQL allows a user to:

    • Select data (flat file)

    • Select data (relational)

    • Order data

    • Insert data

    • Update data

    • Delete records

Selecting data commands (flat file)

Command

Description

Example

SELECT

Retrieves data from a database table

SELECT * FROM users;
(retrieves all data from the ‘users’ table)

SELECT name, age
FROM users
(retrieves names and ages from the ‘users’ table)

FROM

Specifies the tables to retrieve data from

SELECT name, age FROM users;
(retrieves names and ages from the ‘users’ table)

WHERE

Filters the data based on a specified condition

SELECT * FROM users
WHERE age > 30;
(Retrieves users older than 30)

AND

Combines multiple conditions in a WHERE clause

SELECT * FROM users
WHERE age > 18 AND city = ‘New York’;
(retrieves users older than 18 and from New York)

OR

Retrieves data when at least one of the conditions is true

SELECT * FROM users
WHERE age < 18 OR city = ‘New York’;
(retrieves users younger than 18 or from New York)

WILDCARDS

*‘ and ‘%‘ symbols are used for searching and matching data
*‘ used to select all columns in a table
%‘ used as a wildcard character in the LIKE operator

SELECT * FROM users;
(retrieves all columns for the ‘users’ table)

SELECT * FROM users WHERE name LIKE ‘J%’;
(retrieves users whose names start with ‘J’)

Nested SELECT

A select within another select statement (nested). A mini select within the main one

SELECT * FROM users WHERE age > (SELECT AVG(age) FROM users);

(retrieves users with an age greater than the average age)

ORDER BY

How data is organised (sorted) when it is retrieved

SELECT Forename, Lastname FROM Students
WHERE StudentID < 10
ORDER BY Lastname, Forename ASC

(retrieves only the forename and lastname of all students from the students table who have a studentID of less than 10 and displays in ascending order by lastname and forename)

Examples

  • Select all the fields from the Customers table

Command:

SQL query displayed with "SELECT * FROM Customers;" on a black background. The keyword "SELECT" is highlighted in pink.

Output:

Table with column headers: ID, Name, Age, City, Country. Rows of data: 1, John Doe, 30, New York, USA; 2, Jane Doe, 25, London, UK; 3, Peter Lee, 40, Paris, France.
  • Select the ID, name & age of customers who are older than 25

Command:

SQL query to select ID, name, and age from the Customers table where age is greater than 25 with keywords highlighted in pink.

Output:

A table with three columns: ID, Name, and Age. Two rows display data for John Doe (ID 1, Age 30) and Peter Lee (ID 3, Age 40).
  • Select the name and country of customers who are from a country that begins with ‘U’

Command:

SQL query: SELECT Name, Country FROM Customers WHERE Country LIKE 'U%';. The text is white on a black background, with SQL keywords in purple.

Output:

Table with two columns: "Name" and "Country." First row: John Doe, USA. Second row: Jane Doe, UK. The header row is highlighted in blue.
  • Select all fields of customers who are from ‘London’ or ‘Paris’

Command:

<img alt=”SQL query displayed with keywords; selects all records from ‘Customers’ where ‘City’ is ‘London’ or ‘Paris’. Keywords are highlighted in pink.” class=”ContentBlock_figure__vJw2q” data-nimg=”1″ decoding=”a

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注