Back to 课程

Computer-Science-A-level-Ocr

0% Complete
0/0 Steps
  1. 3-3-networks
    8 主题
  2. 3-2-databases
    7 主题
  3. 3-1-compression-encryption-and-hashing
    4 主题
  4. 2-5-object-oriented-languages
    7 主题
  5. 2-4-types-of-programming-language
    4 主题
  6. 2-3-software-development
    5 主题
  7. 2-2-applications-generation
    6 主题
  8. 2-1-systems-software
    8 主题
  9. 1-3-input-output-and-storage
    2 主题
  10. 1-2-types-of-processor
    3 主题
  11. 1-1-structure-and-function-of-the-processor
    1 主题
  12. structuring-your-responses
    3 主题
  13. the-exam-papers
    2 主题
  14. 8-2-algorithms-for-the-main-data-structures
    4 主题
  15. 8-1-algorithms
    10 主题
  16. 7-2-computational-methods
    11 主题
  17. 7-1-programming-techniques
    14 主题
  18. 6-5-thinking-concurrently
    2 主题
  19. 6-4-thinking-logically
    2 主题
  20. 6-3-thinking-procedurally
    3 主题
  21. 6-2-thinking-ahead
    1 主题
  22. 6-1-thinking-abstractly
    3 主题
  23. 5-2-moral-and-ethical-issues
    9 主题
  24. 5-1-computing-related-legislation
    4 主题
  25. 4-3-boolean-algebra
    5 主题
  26. 4-2-data-structures
    10 主题
  27. 4-1-data-types
    9 主题
  28. 3-4-web-technologies
    16 主题
课 Progress
0% Complete

Selecting Data (Single Table)

What is SQL?

  • In A Level Computer Science, SQL (Structured Query Language) is a programming language used to interact with a DBMS.

  • The use of SQL allows a user to:

    • Select data (single table)

    • Select data (multiple tables)

    • Insert data

    • Delete records

    • Delete tables

Selecting data (single table) commands

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)

LIKE

Filters the data based on a specific pattern

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

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’)

Examples

  • Select all the fields from the Customers table

Command:

code

Output:

ID

Name

Age

City

Country

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:

code

Output:

ID

Name

Age

1

John Doe

30

3

Peter Lee

40

  • Select the name and country of customers who are from a country that begins with ‘U’

Command:

code

Output:

Name

Country

John Doe

USA

Jane Doe

UK

  • Select all fields of customers who are from ‘London’ or ‘Paris’

Command:

code

Output:

ID

Name

Age

City

Country

2

Jane Doe

25

London

UK

3

Peter Lee

40

Paris

France

Worked Example

Customers’ details are stored in the flat file database table Customer. An extract of the table is shown below

relational-database

Write the S

Responses

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