SlideShare a Scribd company logo
SQL BASIC QUERIES
WHAT IS SQL
SQL is a standard language for accessing and manipulating databases.
What is SQL?
•SQL stands for Structured Query Language
•SQL lets you access and manipulate databases
•SQL is an ANSI (American National Standards Institute) standard
What Can SQL do?
•SQL can execute queries against a database
•SQL can retrieve data from a database
•SQL can insert, update and create records in a database
•SQL can delete records from 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 can create new databases
REMEMBER
• SQL is NOT case sensitive: select is the same as
SELECT, however it is better to follow the same style.
• Some database systems require a semicolon at the end
of each SQL statement.
• Semicolon is the standard way to separate each SQL
statement in database systems that allow more than
one SQL statement to be executed in the same call to
the server.
SQL QUERIES
• Few important queries are:
• 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
SQL SELECT
• The SELECT statement is used to select data from a
database.The result is stored in a result table, called the
result-set.
• Syntax:
• SELECT column_name,column_name FROM table_name;
and
• SELECT * FROM table_name;
SQL DISTINCT
• The SELECT DISTINCT statement is used to return only distinct
(different) values
• In a table, a column may contain many duplicate values; and
sometimes you only want to list the different (distinct) values. The
DISTINCT keyword can be used to return only distinct (different)
values.
• Syntax
• SELECT DISTINCT column_name,column_name
FROM table_name;
SQL WHERE
• The WHERE clause is used to filter records.
• The WHERE clause is used to extract only those
records that fulfill a specified criterion.
• Syntax
• SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
SQL AND / OR
• The AND & OR operators are used to filter records
based on more than one condition.
• The AND operator displays a record if both the first
condition AND the second condition are true.
• The OR operator displays a record if either the first
condition OR the second condition is true.
• Syntax:
• SELECT * FROM Customers
WHERE Country='Germany'
AND City='Berlin';
SQL ORDER BY
• The ORDER BY keyword is used to sort the result-set.
• The ORDER BY keyword is used to sort the result-set by one or
more columns.
• The ORDER BY keyword sorts the records in ascending order
by default. To sort the records in a descending order, you can
use the DESC keyword.
• Syntax
• SELECT column_name, column_name
FROM table_name
ORDER
BY column_name ASC|DESC, column_name ASC|DES
C;
SQL UPDATE
• The UPDATE statement is used to update existing records in a table.
• Syntax
• UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
• The WHERE clause specifies which record or records that should be
updated. If you omit the WHERE clause, all records will be updated!
SQL DELETE
• The DELETE statement is used to delete records in a table.
• The SQL DELETE Statement
• The DELETE statement is used to delete rows in a table.
• Syntax
• DELETE FROM table_name
WHERE some_column=some_value;
• The WHERE clause specifies which record or records that should be
deleted. If you omit the WHERE clause, all records will be deleted!
SQL SELECT TOP
• The SELECT TOP clause is used to specify the number of
records to return.
• The SELECT TOP clause can be very useful on large tables
with thousands of records. Returning a large number of records
can impact on performance.
• Note: Not all database systems support the SELECT TOP
clause.
• Syntax
• SELECT TOP number|percent column_name(s)
FROM table_name;
SQL LIKE
• The LIKE operator is used in a WHERE clause to search for a specified
pattern in a column.
• The LIKE operator is used to search for a specified pattern in a column.
• Syntax
• SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern;
SQL IN
• The IN operator allows you to specify multiple values in
a WHERE clause.
• Syntax
• SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...);
SQL BETWEEN
• The BETWEEN operator is used to select values within a range.
• The BETWEEN operator selects values within a range. The values can be numbers, text,
or dates.
• Syntax
• SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
SQL ALIAS
• SQL aliases are used to give a database table, or a column in a table, a
temporary name.
• Basically aliases are created to make column names more readable.
• Alias Syntax for Columns
• SELECT column_name AS alias_name
FROM table_name;
• Alias Syntax for Tables
• SELECT column_name(s)
FROM table_name AS alias_name;
SELECT INTO
• With SQL, you can copy information from one table into another.
• The SELECT INTO statement copies data from one table and inserts it into a new table.
• Syntax
• We can copy all columns into the new table:
• SELECT *
INTO newtable
FROM table1;
• Or we can copy only the columns we want into the new table:
• SELECT column_name(s)
INTO newtable FROM table1;
• The new table will be created with the column-names and types as defined in the SELECT
statement. You can apply new names using the AS clause.
•
SQL INSERT
• The INSERT INTO statement is used to insert new records in a table.
• Syntax
• It is possible to write the INSERT INTO statement in two forms.
• The first form does not specify the column names where the data will be
inserted, only their values:
• INSERT INTO table_name
VALUES (value1,value2,value3,...);
• The second form specifies both the column names and the
values to be inserted:
• INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
•
INSERT INTO
• The INSERT INTO SELECT statement copies data from one table and
inserts it into an existing table.
• The INSERT INTO SELECT statement selects data from one table
and inserts it into an existing table. Any existing rows in the target
table are unaffected.
• Syntax
• We can copy all columns from one table to another, existing table:
• INSERT INTO table2
SELECT * FROM table1;
• Or we can copy only the columns we want to into another, existing
table:
• INSERT INTO table2
(column_name(s))
SELECT column_name(s)
FROM table1;
CREATE DATABASE
• The CREATE DATABASE statement is used to create a
database.
• Syntax
• CREATE DATABASE dbname;
• SQL CREATE DATABASE Example
• The following SQL statement creates a database called
"my_db":
• CREATE DATABASE my_db;
CREATE TABLE
• The CREATE TABLE statement is used to create a table in a database.
• Tables are organized into rows and columns; and each table must have a
name.
• Syntax
• CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);
• The column_name parameters specify the names of the columns of the
table.
• The data_type parameter specifies what type of data the column can hold
(e.g. varchar, integer, decimal, date, etc.).
• The size parameter specifies the maximum length of the column of the table.

More Related Content

Similar to 2..basic queries.pptx

MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
HudaRaghibKadhim
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
YashaswiniSrinivasan1
 
Sql
SqlSql
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai1
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
Md.Mojibul Hoque
 
Introduction to Structured Query Language (SQL) (1).ppt
Introduction to Structured Query Language (SQL) (1).pptIntroduction to Structured Query Language (SQL) (1).ppt
Introduction to Structured Query Language (SQL) (1).ppt
ComputerScienceDepar6
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
SherinRappai
 
15925 structured query
15925 structured query15925 structured query
15925 structured query
Universitas Bina Darma Palembang
 
Lec 1 = introduction to structured query language (sql)
Lec 1 = introduction to structured query language (sql)Lec 1 = introduction to structured query language (sql)
Lec 1 = introduction to structured query language (sql)
Faisal Anwar
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
TamiratDejene1
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
Dhani Ahmad
 
SQL
SQLSQL
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
Sheethal Aji Mani
 
3. ddl create
3. ddl create3. ddl create
3. ddl create
Amrit Kaur
 
Introduction to SQL..pdf
Introduction to SQL..pdfIntroduction to SQL..pdf
Introduction to SQL..pdf
mayurisonawane29
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
Md. Mahedee Hasan
 
Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1
sagaroceanic11
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
Abrar ali
 
Session 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdfSession 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdf
SwapnilSaurav7
 

Similar to 2..basic queries.pptx (20)

MySQL Essential Training
MySQL Essential TrainingMySQL Essential Training
MySQL Essential Training
 
ms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptxms-sql-server-150223140402-conversion-gate02.pptx
ms-sql-server-150223140402-conversion-gate02.pptx
 
Sql
SqlSql
Sql
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
Introduction to Structured Query Language (SQL) (1).ppt
Introduction to Structured Query Language (SQL) (1).pptIntroduction to Structured Query Language (SQL) (1).ppt
Introduction to Structured Query Language (SQL) (1).ppt
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
15925 structured query
15925 structured query15925 structured query
15925 structured query
 
Lec 1 = introduction to structured query language (sql)
Lec 1 = introduction to structured query language (sql)Lec 1 = introduction to structured query language (sql)
Lec 1 = introduction to structured query language (sql)
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
SQL
SQLSQL
SQL
 
Relational Database Language.pptx
Relational Database Language.pptxRelational Database Language.pptx
Relational Database Language.pptx
 
3. ddl create
3. ddl create3. ddl create
3. ddl create
 
Introduction to SQL..pdf
Introduction to SQL..pdfIntroduction to SQL..pdf
Introduction to SQL..pdf
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
MS SQL Server
MS SQL ServerMS SQL Server
MS SQL Server
 
Sql overview-1232931296681161-1
Sql overview-1232931296681161-1Sql overview-1232931296681161-1
Sql overview-1232931296681161-1
 
Database COMPLETE
Database COMPLETEDatabase COMPLETE
Database COMPLETE
 
Session 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdfSession 1 - Databases-JUNE 2023.pdf
Session 1 - Databases-JUNE 2023.pdf
 

Recently uploaded

Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
NgcHiNguyn25
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 

Recently uploaded (20)

Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Life upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for studentLife upper-Intermediate B2 Workbook for student
Life upper-Intermediate B2 Workbook for student
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 

2..basic queries.pptx

  • 2. WHAT IS SQL SQL is a standard language for accessing and manipulating databases. What is SQL? •SQL stands for Structured Query Language •SQL lets you access and manipulate databases •SQL is an ANSI (American National Standards Institute) standard What Can SQL do? •SQL can execute queries against a database •SQL can retrieve data from a database •SQL can insert, update and create records in a database •SQL can delete records from 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 can create new databases
  • 3. REMEMBER • SQL is NOT case sensitive: select is the same as SELECT, however it is better to follow the same style. • Some database systems require a semicolon at the end of each SQL statement. • Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.
  • 4. SQL QUERIES • Few important queries are: • 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
  • 5. SQL SELECT • The SELECT statement is used to select data from a database.The result is stored in a result table, called the result-set. • Syntax: • SELECT column_name,column_name FROM table_name; and • SELECT * FROM table_name;
  • 6. SQL DISTINCT • The SELECT DISTINCT statement is used to return only distinct (different) values • In a table, a column may contain many duplicate values; and sometimes you only want to list the different (distinct) values. The DISTINCT keyword can be used to return only distinct (different) values. • Syntax • SELECT DISTINCT column_name,column_name FROM table_name;
  • 7. SQL WHERE • The WHERE clause is used to filter records. • The WHERE clause is used to extract only those records that fulfill a specified criterion. • Syntax • SELECT column_name,column_name FROM table_name WHERE column_name operator value;
  • 8. SQL AND / OR • The AND & OR operators are used to filter records based on more than one condition. • The AND operator displays a record if both the first condition AND the second condition are true. • The OR operator displays a record if either the first condition OR the second condition is true. • Syntax: • SELECT * FROM Customers WHERE Country='Germany' AND City='Berlin';
  • 9. SQL ORDER BY • The ORDER BY keyword is used to sort the result-set. • The ORDER BY keyword is used to sort the result-set by one or more columns. • The ORDER BY keyword sorts the records in ascending order by default. To sort the records in a descending order, you can use the DESC keyword. • Syntax • SELECT column_name, column_name FROM table_name ORDER BY column_name ASC|DESC, column_name ASC|DES C;
  • 10. SQL UPDATE • The UPDATE statement is used to update existing records in a table. • Syntax • UPDATE table_name SET column1=value1,column2=value2,... WHERE some_column=some_value; • The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated!
  • 11. SQL DELETE • The DELETE statement is used to delete records in a table. • The SQL DELETE Statement • The DELETE statement is used to delete rows in a table. • Syntax • DELETE FROM table_name WHERE some_column=some_value; • The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!
  • 12. SQL SELECT TOP • The SELECT TOP clause is used to specify the number of records to return. • The SELECT TOP clause can be very useful on large tables with thousands of records. Returning a large number of records can impact on performance. • Note: Not all database systems support the SELECT TOP clause. • Syntax • SELECT TOP number|percent column_name(s) FROM table_name;
  • 13. SQL LIKE • The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. • The LIKE operator is used to search for a specified pattern in a column. • Syntax • SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern;
  • 14. SQL IN • The IN operator allows you to specify multiple values in a WHERE clause. • Syntax • SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...);
  • 15. SQL BETWEEN • The BETWEEN operator is used to select values within a range. • The BETWEEN operator selects values within a range. The values can be numbers, text, or dates. • Syntax • SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;
  • 16. SQL ALIAS • SQL aliases are used to give a database table, or a column in a table, a temporary name. • Basically aliases are created to make column names more readable. • Alias Syntax for Columns • SELECT column_name AS alias_name FROM table_name; • Alias Syntax for Tables • SELECT column_name(s) FROM table_name AS alias_name;
  • 17. SELECT INTO • With SQL, you can copy information from one table into another. • The SELECT INTO statement copies data from one table and inserts it into a new table. • Syntax • We can copy all columns into the new table: • SELECT * INTO newtable FROM table1; • Or we can copy only the columns we want into the new table: • SELECT column_name(s) INTO newtable FROM table1; • The new table will be created with the column-names and types as defined in the SELECT statement. You can apply new names using the AS clause. •
  • 18. SQL INSERT • The INSERT INTO statement is used to insert new records in a table. • Syntax • It is possible to write the INSERT INTO statement in two forms. • The first form does not specify the column names where the data will be inserted, only their values: • INSERT INTO table_name VALUES (value1,value2,value3,...); • The second form specifies both the column names and the values to be inserted: • INSERT INTO table_name (column1,column2,column3,...) VALUES (value1,value2,value3,...); •
  • 19. INSERT INTO • The INSERT INTO SELECT statement copies data from one table and inserts it into an existing table. • The INSERT INTO SELECT statement selects data from one table and inserts it into an existing table. Any existing rows in the target table are unaffected. • Syntax • We can copy all columns from one table to another, existing table: • INSERT INTO table2 SELECT * FROM table1; • Or we can copy only the columns we want to into another, existing table: • INSERT INTO table2 (column_name(s)) SELECT column_name(s) FROM table1;
  • 20. CREATE DATABASE • The CREATE DATABASE statement is used to create a database. • Syntax • CREATE DATABASE dbname; • SQL CREATE DATABASE Example • The following SQL statement creates a database called "my_db": • CREATE DATABASE my_db;
  • 21. CREATE TABLE • The CREATE TABLE statement is used to create a table in a database. • Tables are organized into rows and columns; and each table must have a name. • Syntax • CREATE TABLE table_name ( column_name1 data_type(size), column_name2 data_type(size), column_name3 data_type(size), .... ); • The column_name parameters specify the names of the columns of the table. • The data_type parameter specifies what type of data the column can hold (e.g. varchar, integer, decimal, date, etc.). • The size parameter specifies the maximum length of the column of the table.