0% found this document useful (0 votes)
3 views

Retrieving and Updating Data SQL

This document is a beginner-friendly guide to SQL, explaining core operations such as retrieving and updating data in databases. It covers the use of the SELECT statement for data retrieval, the UPDATE statement for modifying existing data, and the importance of the WHERE clause for filtering results. Additionally, it provides examples and a real-world workflow for managing database information.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Retrieving and Updating Data SQL

This document is a beginner-friendly guide to SQL, explaining core operations such as retrieving and updating data in databases. It covers the use of the SELECT statement for data retrieval, the UPDATE statement for modifying existing data, and the importance of the WHERE clause for filtering results. Additionally, it provides examples and a real-world workflow for managing database information.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Retrieving and Updating Data in

SQL
• A Beginner-Friendly Guide to Core SQL
Operations
• Your Name • Date • Class Info
What is SQL and a Database?
• SQL (Structured Query Language) is used to
manage databases.
• A database stores data in tables (like
spreadsheets).
• Each table has rows (records) and columns
(fields).

• Example Table – students:


• id | name | age
Retrieving Data – SELECT
• The SELECT statement is used to retrieve/view
data from a table.

• Syntax:
• SELECT column1, column2 FROM table_name;

• Example:
• SELECT name, age FROM students;
• (Returns just the name and age of all
Using * and WHERE
• * selects all columns; WHERE filters rows
based on conditions.

• Example:
• SELECT * FROM students;
• (Get all data from students table.)

• SELECT * FROM students WHERE age > 21;


• (Returns students older than 21.)
More SELECT Options
• Use ORDER BY to sort results.
• Use WHERE to filter specific rows.

• Example:
• SELECT * FROM students ORDER BY age DESC;
• (Sorts by age in descending order.)

• SELECT * FROM students WHERE name = 'Jane


Smith';
Updating Data – UPDATE
• UPDATE modifies existing data in a table.
• Always use WHERE to target specific rows.

• Syntax:
• UPDATE table_name SET column1 = value1
WHERE condition;

• Example:
• UPDATE students SET age = 23 WHERE name =
Updating Multiple Columns
• You can update multiple values at once.

• Example:
• UPDATE students SET name = 'Janet Smith',
age = 24 WHERE id = 2;
• (Changes name and age for id 2.)
Verifying with SELECT
• After updating, use SELECT to confirm
changes.

• Example:
• SELECT * FROM students WHERE id = 2;
• (This checks if the update worked correctly.)
Real-World Flow Example
• 1. SELECT to view current data.
• 2. Identify incorrect/outdated info.
• 3. UPDATE to fix data.
• 4. SELECT again to verify changes.

• This is a common real-world database


workflow.
Summary & Practice
• RECAP:
• - SELECT: View data
• - UPDATE: Change data
• - WHERE: Filter rows
• - *: All columns

• Practice at:
• - sqlbolt.com
• - w3schools.com/sql

You might also like