0% found this document useful (0 votes)
2 views7 pages

SQL Query

This document provides an introduction to SQL (Structured Query Language), detailing its purpose, capabilities, and standardization by ANSI and ISO. It outlines essential SQL commands, syntax for data manipulation, and examples of using SELECT, INSERT, UPDATE, and DELETE statements. Additionally, it explains the use of clauses like WHERE, ORDER BY, and operators such as AND, OR, and NOT in SQL queries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views7 pages

SQL Query

This document provides an introduction to SQL (Structured Query Language), detailing its purpose, capabilities, and standardization by ANSI and ISO. It outlines essential SQL commands, syntax for data manipulation, and examples of using SELECT, INSERT, UPDATE, and DELETE statements. Additionally, it explains the use of clauses like WHERE, ORDER BY, and operators such as AND, OR, and NOT in SQL queries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

University of Aden

Faculty of Engineering
Department of Information Technology

MADE BY:
Engener: Nadhem Mahyoub Mohammed

Abril-2025
SQL INTRO:
What is SQL?
 SQL stands for Structured Query Language
 SQL lets you access and manipulate databases
 SQL became a standard of the American National Standards
Institute (ANSI) in 1986, and of the International Organization for
Standardization (ISO) in 1987

What Can SQL do?


 SQL can execute queries against a database
 SQL can retrieve data from a database
 SQL can insert records in a database
 SQL can update records in a database
 SQL can delete records from a database
 SQL can create new databases
 SQL can create new tables in a database
 SQL can create stored procedures in a database
 SQL can create views in a database
 SQL can set permissions on tables, procedures, and views

SQL is a Standard - BUT....


Although SQL is an ANSI/ISO standard, there are different versions of the
SQL language.

However, to be compliant with the ANSI standard, they all support at least
the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a
similar manner.

SQL Syntax :
Example
Select all records from the Customers table:

SELECT * FROM Customers;

I
Made By : Eng Nadhem Al-Hashmy
Contact :+967-773526470
Some of The Most Important SQL
Commands
 SELECT - extracts data from a database
 UPDATE - updates data in a database
 DELETE - deletes data from a database
 INSERT INTO - inserts new data into a database
 CREATE DATABASE - creates a new database
 ALTER DATABASE - modifies a database
 CREATE TABLE - creates a new table
 ALTER TABLE - modifies a table
 DROP TABLE - deletes a table
 CREATE INDEX - creates an index (search key)
 DROP INDEX - deletes an index

The SQL SELECT Statement


Syntax
SELECT column1, column2, ...
FROM table_name;

Example
Return all the columns from the Customers table:

SELECT * FROM Customers;

The SQL SELECT DISTINCT Statement


The SELECT DISTINCT statement is used to return only distinct (different)
values.

SELECT DISTINCT Country FROM Customers;

Syntax
SELECT DISTINCT column1, column2, ...
FROM table_name;
II
Made By : Eng Nadhem Al-Hashmy
Contact :+967-773526470
Example
Select all the different countries from the "Customers" table:

SELECT DISTINCT Country FROM Customers;

The SQL WHERE Clause


The WHERE clause is used to filter records.

It is used to extract only those records that fulfill a specified condition.

Example
Select all customers from Mexico:

SELECT * FROM Customers


WHERE Country='Mexico';
Note: The WHERE clause is not only used in SELECT statements, it is also
used in UPDATE, DELETE, etc.

The SQL ORDER BY


The ORDER BY keyword is used to sort the result-set in ascending or
descending order.

Syntax
SELECT column1, column2, ...
FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

Example
Sort the products by price:

SELECT * FROM Products


ORDER BY Price;

The SQL AND Operator


The WHERE clause can contain one or many AND operators.

III
Made By : Eng Nadhem Al-Hashmy
Contact :+967-773526470
The AND operator is used to filter records based on more than one
condition, like if you want to return all customers from Spain that starts
with the letter 'G':

Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 AND condition2 AND condition3 ...;

Example
Select all customers from Spain that starts with the letter 'G':
SELECT *
FROM Customers
WHERE Country = 'Spain' AND CustomerName LIKE 'G%';

The SQL OR Operator


The WHERE clause can contain one or more OR operators.

The OR operator is used to filter records based on more than one


condition, like if you want to return all customers from Germany but also
those from Spain:

Example
Select all customers from Germany or Spain:

SELECT *
FROM Customers
WHERE Country = 'Germany' OR Country = 'Spain';

The NOT Operator


The NOT operator is used in combination with other operators to give the
opposite result, also called the negative result.

In the select statement below we want to return all customers that are
NOT from Spain:

Example
Select only the customers that are NOT from Spain:
IV
Made By : Eng Nadhem Al-Hashmy
Contact :+967-773526470
SELECT * FROM Customers
WHERE NOT Country = 'Spain';

The SQL INSERT INTO Statement


The INSERT INTO statement is used to insert new records in a table.

INSERT INTO Syntax


It is possible to write the INSERT INTO statement in two ways:

1. Specify both the column names and the values to be inserted:

INSERT INTO table_name (column1, column2, column3, ...)


VALUES (value1, value2, value3, ...);

2. If you are adding values for all the columns of the table, you do not
need to specify the column names in the SQL query. However, make sure
the order of the values is in the same order as the columns in the table.
Here, the INSERT INTO syntax would be as follows:

INSERT INTO table_name


VALUES (value1, value2, value3, ...);

What is a NULL Value?


A field with a NULL value is a field with no value.

How to Test for NULL Values?


It is not possible to test for NULL values with comparison operators, such
as =, <, or <>.

We will have to use the IS NULL and IS NOT NULL operators instead.

IS NULL Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NULL;

V
Made By : Eng Nadhem Al-Hashmy
Contact :+967-773526470
IS NOT NULL Syntax
SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;

VI
Made By : Eng Nadhem Al-Hashmy
Contact :+967-773526470

You might also like