SlideShare une entreprise Scribd logo
1  sur  23
SQL SELECT DISTINCT
Statement
 In a table, some of the columns may contain
duplicate values. This is not a problem,
however, sometimes you will want to list only
the different (distinct) values in a table.
 The DISTINCT keyword can be used to return
only distinct (different) values.
 SQL SELECT DISTINCT Syntax
SELECT DISTINCT column_name(s)
FROM table_name
SELECT DISTINCT Person.PName
FROM Person;
Id Name Address Hobby
1123 Anita Damauli stamps
1123 Anita Damauli coins
5556 Binod
Kathmand
u
hiking
9876 Barsha
Kathmand
u
stamps
PName
Anita
Barsha
Binod
SQL AND & OR Operators
 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.
SQL OR Operators
SELECT * FROM Person
WHERE Person.Hobby='hiking' OR
Person.ID>3000;
ID PName Address Hobby
5556 Binod Kathmandu hiking
9876 Barsha Kathmandu stamps
SQL AND Operators
SELECT *
FROM Person
WHERE Person.ID>3000 AND Person.ID<5999;
ID PName Address Hobby
5556 Binod Kathmandu hiking
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 a specified column.
 The ORDER BY keyword sorts the records in
ascending order by default.
 If you want to sort the records in a descending
order, you can use the DESC keyword.
SQL ORDER BY Syntax
 SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC|DESC
SELECT Person.Hobby
FROM Person
ORDER BY Person.Hobby;
Hobby
coins
hiking
stamps
stamps
SQL INSERT INTO
 The INSERT INTO statement is used to insert a new
row in a table.
SQL INSERT INTO Syntax
 It is possible to write the INSERT INTO statement in
two forms.
 The first form doesn't 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,...)
SQL INSERT INTO
 INSERT INTO Persons
VALUES (4,'Nilsen', 'Johan', 'Bakken 2',
'Stavanger')
 INSERT INTO Persons (P_Id, LastName,
FirstName)
VALUES (5, 'Tjessem', 'Jakob')
SQL UPDATE
The UPDATE statement is used to update
existing records in a table.
SQL UPDATE Syntax:
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
Example:
UPDATE Persons
SET Address=‘Nayabazar', City=‘Kathmandu'
WHERE LastName=‘Ghimire' AND
FirstName=‘Bishal'
SQL UPDATE Warning
 Be careful when updating records. If we had
omitted the WHERE clause in the example
above, like this:
UPDATE Persons
SET Address=‘Nayabazar', City=‘Kathmandu‘
What will be the result ?
SQL DELETE
 The DELETE statement is used to delete rows
in a table.
SQL DELETE Syntax
DELETE FROM table_name
WHERE some_column=some_value
DELETE FROM Persons
WHERE Address=‘Nayabazar', City=‘Kathmandu‘
SQL TOP
 The TOP clause is used to specify the number
of records to return.
 The 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
TOP clause.
 SQL Server Syntax
 SELECT TOP number|percent column_name(s)
FROM table_name
SQL TOP
 MySQL Syntax
 SELECT column_name(s)
FROM table_name
LIMIT number
 Oracle Syntax
 SELECT column_name(s)
FROM table_name
WHERE ROWNUM <= number
 SELECT * FROM Persons LIMIT 5
SQL LIKE
 The LIKE operator is used to search for a
specified pattern in a column.
 SQL LIKE Syntax
 SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern
SQL LIKE
 To select the persons living in a city that starts
with "s" from the table.
 SELECT * FROM Persons
WHERE City LIKE ‘k%'
SQL Wildcards
Wildcard Description
% A substitute for zero or more characters
_ A substitute for exactly one character
[charlist] Any single character in charlist
[^charlist]or
[!charlist]
Any single character not in charlist
• SQL wildcards can substitute for one or more
characters when searching for data in a
database.
• SQL wildcards must be used with the SQL
LIKE operator.
SQL IN
 The IN operator allows you to specify multiple
values in a WHERE clause.
 SQL IN Syntax
 SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...)
 Example #1
Select *
From Address
Where FirstName IN ('Mary', 'Sam')
 Example #2
SELECT *
FROM Address
WHERE FirstName = 'Mary'
OR FirstName = 'Sam'
SQL BETWEEN
 The BETWEEN operator selects a range of
data between two values. The values can be
numbers, text, or dates.
 SQL BETWEEN Syntax
 SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
 Example:
 SELECT * FROM suppliers WHERE supplier_id
BETWEEN 5000 AND 5010;
 SELECT * FROM suppliers WHERE supplier_id
>= 5000 AND supplier_id <= 5010;
 example:
 SELECT * FROM orders WHERE order_date
between to_date ('2013/01/01', 'yyyy/mm/dd')
AND to_date ('2013/12/31', 'yyyy/mm/dd');
 SELECT * FROM orders WHERE order_date >=
to_date('2013/01/01', 'yyyy/mm/dd') AND
order_date <=
to_date('2013/12/31','yyyy/mm/dd');

Contenu connexe

Tendances (20)

SQL subquery
SQL subquerySQL subquery
SQL subquery
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Commands of DML in SQL
Commands of DML in SQLCommands of DML in SQL
Commands of DML in SQL
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
Database Keys
Database KeysDatabase Keys
Database Keys
 
SQL commands
SQL commandsSQL commands
SQL commands
 
Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause Group By, Having Clause and Order By clause
Group By, Having Clause and Order By clause
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
Sql operator
Sql operatorSql operator
Sql operator
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
SQL JOIN
SQL JOINSQL JOIN
SQL JOIN
 
Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Trigger
TriggerTrigger
Trigger
 
MYSQL Aggregate Functions
MYSQL Aggregate FunctionsMYSQL Aggregate Functions
MYSQL Aggregate Functions
 
Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)Presentation slides of Sequence Query Language (SQL)
Presentation slides of Sequence Query Language (SQL)
 
Ms sql-server
Ms sql-serverMs sql-server
Ms sql-server
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
MySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs AcademyMySql Triggers Tutorial - The Webs Academy
MySql Triggers Tutorial - The Webs Academy
 
Triggers in SQL | Edureka
Triggers in SQL | EdurekaTriggers in SQL | Edureka
Triggers in SQL | Edureka
 

En vedette

Prestations et aides sociales, le dérapage incontrôlé
Prestations et aides sociales, le dérapage incontrôléPrestations et aides sociales, le dérapage incontrôlé
Prestations et aides sociales, le dérapage incontrôléFondation iFRAP
 
嶺南 完成版 With Reference By Vince Cheung
嶺南 完成版 With Reference  By Vince Cheung嶺南 完成版 With Reference  By Vince Cheung
嶺南 完成版 With Reference By Vince Cheungalexwong1215
 
Setting Up Stock Broking Business in Vietnam
Setting Up Stock Broking Business in VietnamSetting Up Stock Broking Business in Vietnam
Setting Up Stock Broking Business in VietnamDennis Ooi
 
[Paper introduction] Performance Capture of Interacting Characters with Handh...
[Paper introduction] Performance Capture of Interacting Characters with Handh...[Paper introduction] Performance Capture of Interacting Characters with Handh...
[Paper introduction] Performance Capture of Interacting Characters with Handh...Mitsuru Nakazawa
 
Funding outlook for training providers by Safaraz Ali April 2015
Funding outlook for training providers by Safaraz Ali April 2015Funding outlook for training providers by Safaraz Ali April 2015
Funding outlook for training providers by Safaraz Ali April 2015The Pathway Group
 
15 May 2015
15 May 201515 May 2015
15 May 2015ssktimes
 
Knives, Sharpeners, Scissors, Graters and Hooks.
Knives, Sharpeners, Scissors, Graters and Hooks.Knives, Sharpeners, Scissors, Graters and Hooks.
Knives, Sharpeners, Scissors, Graters and Hooks.Eong Huat Indoor Sales
 
TestBird - Mobile Game Testing Report(Sample)
TestBird - Mobile Game Testing Report(Sample)TestBird - Mobile Game Testing Report(Sample)
TestBird - Mobile Game Testing Report(Sample)TestBird
 
Tmw20116 brooks.l
Tmw20116 brooks.lTmw20116 brooks.l
Tmw20116 brooks.lnavaidkhan
 
Resume: Research Engineer
Resume: Research Engineer Resume: Research Engineer
Resume: Research Engineer Abhishek Singh
 

En vedette (20)

Marketing pitch
Marketing pitchMarketing pitch
Marketing pitch
 
Prestations et aides sociales, le dérapage incontrôlé
Prestations et aides sociales, le dérapage incontrôléPrestations et aides sociales, le dérapage incontrôlé
Prestations et aides sociales, le dérapage incontrôlé
 
CIRCULAR IPC FEBRERO 2016
CIRCULAR IPC FEBRERO 2016CIRCULAR IPC FEBRERO 2016
CIRCULAR IPC FEBRERO 2016
 
嶺南 完成版 With Reference By Vince Cheung
嶺南 完成版 With Reference  By Vince Cheung嶺南 完成版 With Reference  By Vince Cheung
嶺南 完成版 With Reference By Vince Cheung
 
معلم التجويد
معلم التجويدمعلم التجويد
معلم التجويد
 
Setting Up Stock Broking Business in Vietnam
Setting Up Stock Broking Business in VietnamSetting Up Stock Broking Business in Vietnam
Setting Up Stock Broking Business in Vietnam
 
[Paper introduction] Performance Capture of Interacting Characters with Handh...
[Paper introduction] Performance Capture of Interacting Characters with Handh...[Paper introduction] Performance Capture of Interacting Characters with Handh...
[Paper introduction] Performance Capture of Interacting Characters with Handh...
 
Walden UDL PPT
Walden UDL PPTWalden UDL PPT
Walden UDL PPT
 
gghjkl
gghjklgghjkl
gghjkl
 
Funding outlook for training providers by Safaraz Ali April 2015
Funding outlook for training providers by Safaraz Ali April 2015Funding outlook for training providers by Safaraz Ali April 2015
Funding outlook for training providers by Safaraz Ali April 2015
 
15 May 2015
15 May 201515 May 2015
15 May 2015
 
Ee 2484i
Ee 2484iEe 2484i
Ee 2484i
 
Knives, Sharpeners, Scissors, Graters and Hooks.
Knives, Sharpeners, Scissors, Graters and Hooks.Knives, Sharpeners, Scissors, Graters and Hooks.
Knives, Sharpeners, Scissors, Graters and Hooks.
 
History and actors of nonviolence. — 06. From 1939 to 1949
History and actors of nonviolence. — 06. From 1939 to 1949History and actors of nonviolence. — 06. From 1939 to 1949
History and actors of nonviolence. — 06. From 1939 to 1949
 
TestBird - Mobile Game Testing Report(Sample)
TestBird - Mobile Game Testing Report(Sample)TestBird - Mobile Game Testing Report(Sample)
TestBird - Mobile Game Testing Report(Sample)
 
Apple 301
Apple 301Apple 301
Apple 301
 
Sfdfdf
SfdfdfSfdfdf
Sfdfdf
 
Tmw20116 brooks.l
Tmw20116 brooks.lTmw20116 brooks.l
Tmw20116 brooks.l
 
hlooooooo
hlooooooohlooooooo
hlooooooo
 
Resume: Research Engineer
Resume: Research Engineer Resume: Research Engineer
Resume: Research Engineer
 

Similaire à 06.01 sql select distinct

Similaire à 06.01 sql select distinct (20)

MY SQL
MY SQLMY SQL
MY SQL
 
SQL
SQLSQL
SQL
 
Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01Mysql 120831075600-phpapp01
Mysql 120831075600-phpapp01
 
Sql – Structured Query Language
Sql – Structured Query LanguageSql – Structured Query Language
Sql – Structured Query Language
 
SQL notes 1.pdf
SQL notes 1.pdfSQL notes 1.pdf
SQL notes 1.pdf
 
SQL Tutorial for Beginners
SQL Tutorial for BeginnersSQL Tutorial for Beginners
SQL Tutorial for Beginners
 
SQL
SQLSQL
SQL
 
SQL
SQLSQL
SQL
 
SQL Language
SQL LanguageSQL Language
SQL Language
 
Query
QueryQuery
Query
 
MS SQL Server 1
MS SQL Server 1MS SQL Server 1
MS SQL Server 1
 
Sql slid
Sql slidSql slid
Sql slid
 
Database Management System 1
Database Management System 1Database Management System 1
Database Management System 1
 
Sql
SqlSql
Sql
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
Sql practise for beginners
Sql practise for beginnersSql practise for beginners
Sql practise for beginners
 
SQL report
SQL reportSQL report
SQL report
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsgADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
ADBMS unit 1.pdfsdgdsgdsgdsgdsgdsgdsgdsg
 
Bibashsql
BibashsqlBibashsql
Bibashsql
 

Plus de Bishal Ghimire

Counseling Ethics in Astrology for better Mental Health
Counseling Ethics in Astrology for better Mental HealthCounseling Ethics in Astrology for better Mental Health
Counseling Ethics in Astrology for better Mental HealthBishal Ghimire
 
Agile Intro to Manifesto - Values 1 - Interaction over Process
Agile Intro to Manifesto - Values 1 - Interaction over ProcessAgile Intro to Manifesto - Values 1 - Interaction over Process
Agile Intro to Manifesto - Values 1 - Interaction over ProcessBishal Ghimire
 
Earthquake in Nepal 2015
Earthquake in Nepal 2015Earthquake in Nepal 2015
Earthquake in Nepal 2015Bishal Ghimire
 
09.02 normalization example
09.02 normalization example09.02 normalization example
09.02 normalization exampleBishal Ghimire
 
07.03 cartesian product
07.03 cartesian product07.03 cartesian product
07.03 cartesian productBishal Ghimire
 
07.02 relational union intersection
07.02 relational union intersection07.02 relational union intersection
07.02 relational union intersectionBishal Ghimire
 
07.01 relational algebra
07.01 relational algebra07.01 relational algebra
07.01 relational algebraBishal Ghimire
 
07.01 relational algebra
07.01 relational algebra07.01 relational algebra
07.01 relational algebraBishal Ghimire
 
04.01 file organization
04.01 file organization04.01 file organization
04.01 file organizationBishal Ghimire
 
02.02 querying relational database
02.02 querying relational database02.02 querying relational database
02.02 querying relational databaseBishal Ghimire
 
02.01 relational databases
02.01 relational databases02.01 relational databases
02.01 relational databasesBishal Ghimire
 
01.01 introduction to database
01.01 introduction to database01.01 introduction to database
01.01 introduction to databaseBishal Ghimire
 
00.00 fundamentals of database management syllabus
00.00 fundamentals of database management syllabus00.00 fundamentals of database management syllabus
00.00 fundamentals of database management syllabusBishal Ghimire
 

Plus de Bishal Ghimire (17)

Counseling Ethics in Astrology for better Mental Health
Counseling Ethics in Astrology for better Mental HealthCounseling Ethics in Astrology for better Mental Health
Counseling Ethics in Astrology for better Mental Health
 
Agile Intro to Manifesto - Values 1 - Interaction over Process
Agile Intro to Manifesto - Values 1 - Interaction over ProcessAgile Intro to Manifesto - Values 1 - Interaction over Process
Agile Intro to Manifesto - Values 1 - Interaction over Process
 
Earthquake in Nepal 2015
Earthquake in Nepal 2015Earthquake in Nepal 2015
Earthquake in Nepal 2015
 
09.02 normalization example
09.02 normalization example09.02 normalization example
09.02 normalization example
 
07.05 division
07.05 division07.05 division
07.05 division
 
07.04 joins
07.04 joins07.04 joins
07.04 joins
 
07.03 cartesian product
07.03 cartesian product07.03 cartesian product
07.03 cartesian product
 
07.02 relational union intersection
07.02 relational union intersection07.02 relational union intersection
07.02 relational union intersection
 
07.01 relational algebra
07.01 relational algebra07.01 relational algebra
07.01 relational algebra
 
07.01 relational algebra
07.01 relational algebra07.01 relational algebra
07.01 relational algebra
 
09.01 normalization
09.01 normalization09.01 normalization
09.01 normalization
 
06.02 sql alias
06.02 sql alias06.02 sql alias
06.02 sql alias
 
04.01 file organization
04.01 file organization04.01 file organization
04.01 file organization
 
02.02 querying relational database
02.02 querying relational database02.02 querying relational database
02.02 querying relational database
 
02.01 relational databases
02.01 relational databases02.01 relational databases
02.01 relational databases
 
01.01 introduction to database
01.01 introduction to database01.01 introduction to database
01.01 introduction to database
 
00.00 fundamentals of database management syllabus
00.00 fundamentals of database management syllabus00.00 fundamentals of database management syllabus
00.00 fundamentals of database management syllabus
 

Dernier

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 

Dernier (20)

Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 

06.01 sql select distinct

  • 1.
  • 2. SQL SELECT DISTINCT Statement  In a table, some of the columns may contain duplicate values. This is not a problem, however, sometimes you will want to list only the different (distinct) values in a table.  The DISTINCT keyword can be used to return only distinct (different) values.  SQL SELECT DISTINCT Syntax SELECT DISTINCT column_name(s) FROM table_name
  • 3. SELECT DISTINCT Person.PName FROM Person; Id Name Address Hobby 1123 Anita Damauli stamps 1123 Anita Damauli coins 5556 Binod Kathmand u hiking 9876 Barsha Kathmand u stamps PName Anita Barsha Binod
  • 4. SQL AND & OR Operators  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.
  • 5. SQL OR Operators SELECT * FROM Person WHERE Person.Hobby='hiking' OR Person.ID>3000; ID PName Address Hobby 5556 Binod Kathmandu hiking 9876 Barsha Kathmandu stamps
  • 6. SQL AND Operators SELECT * FROM Person WHERE Person.ID>3000 AND Person.ID<5999; ID PName Address Hobby 5556 Binod Kathmandu hiking
  • 7. 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 a specified column.  The ORDER BY keyword sorts the records in ascending order by default.  If you want to sort the records in a descending order, you can use the DESC keyword.
  • 8. SQL ORDER BY Syntax  SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC SELECT Person.Hobby FROM Person ORDER BY Person.Hobby; Hobby coins hiking stamps stamps
  • 9. SQL INSERT INTO  The INSERT INTO statement is used to insert a new row in a table. SQL INSERT INTO Syntax  It is possible to write the INSERT INTO statement in two forms.  The first form doesn't 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,...)
  • 10. SQL INSERT INTO  INSERT INTO Persons VALUES (4,'Nilsen', 'Johan', 'Bakken 2', 'Stavanger')  INSERT INTO Persons (P_Id, LastName, FirstName) VALUES (5, 'Tjessem', 'Jakob')
  • 11. SQL UPDATE The UPDATE statement is used to update existing records in a table. SQL UPDATE Syntax: UPDATE table_name SET column1=value, column2=value2,... WHERE some_column=some_value Example: UPDATE Persons SET Address=‘Nayabazar', City=‘Kathmandu' WHERE LastName=‘Ghimire' AND FirstName=‘Bishal'
  • 12. SQL UPDATE Warning  Be careful when updating records. If we had omitted the WHERE clause in the example above, like this: UPDATE Persons SET Address=‘Nayabazar', City=‘Kathmandu‘ What will be the result ?
  • 13. SQL DELETE  The DELETE statement is used to delete rows in a table. SQL DELETE Syntax DELETE FROM table_name WHERE some_column=some_value DELETE FROM Persons WHERE Address=‘Nayabazar', City=‘Kathmandu‘
  • 14. SQL TOP  The TOP clause is used to specify the number of records to return.  The 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 TOP clause.  SQL Server Syntax  SELECT TOP number|percent column_name(s) FROM table_name
  • 15. SQL TOP  MySQL Syntax  SELECT column_name(s) FROM table_name LIMIT number  Oracle Syntax  SELECT column_name(s) FROM table_name WHERE ROWNUM <= number  SELECT * FROM Persons LIMIT 5
  • 16. SQL LIKE  The LIKE operator is used to search for a specified pattern in a column.  SQL LIKE Syntax  SELECT column_name(s) FROM table_name WHERE column_name LIKE pattern
  • 17. SQL LIKE  To select the persons living in a city that starts with "s" from the table.  SELECT * FROM Persons WHERE City LIKE ‘k%'
  • 18. SQL Wildcards Wildcard Description % A substitute for zero or more characters _ A substitute for exactly one character [charlist] Any single character in charlist [^charlist]or [!charlist] Any single character not in charlist • SQL wildcards can substitute for one or more characters when searching for data in a database. • SQL wildcards must be used with the SQL LIKE operator.
  • 19. SQL IN  The IN operator allows you to specify multiple values in a WHERE clause.  SQL IN Syntax  SELECT column_name(s) FROM table_name WHERE column_name IN (value1,value2,...)
  • 20.  Example #1 Select * From Address Where FirstName IN ('Mary', 'Sam')  Example #2 SELECT * FROM Address WHERE FirstName = 'Mary' OR FirstName = 'Sam'
  • 21. SQL BETWEEN  The BETWEEN operator selects a range of data between two values. The values can be numbers, text, or dates.  SQL BETWEEN Syntax  SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2
  • 22.  Example:  SELECT * FROM suppliers WHERE supplier_id BETWEEN 5000 AND 5010;  SELECT * FROM suppliers WHERE supplier_id >= 5000 AND supplier_id <= 5010;
  • 23.  example:  SELECT * FROM orders WHERE order_date between to_date ('2013/01/01', 'yyyy/mm/dd') AND to_date ('2013/12/31', 'yyyy/mm/dd');  SELECT * FROM orders WHERE order_date >= to_date('2013/01/01', 'yyyy/mm/dd') AND order_date <= to_date('2013/12/31','yyyy/mm/dd');