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 JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Complex queries in sql
Complex queries in sqlComplex queries in sql
Complex queries in sql
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Training
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
SQL
SQLSQL
SQL
 
Sql joins
Sql joinsSql joins
Sql joins
 
SQL
SQLSQL
SQL
 
Sql join
Sql  joinSql  join
Sql join
 
Nested Queries Lecture
Nested Queries LectureNested Queries Lecture
Nested Queries Lecture
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
Mysql joins
Mysql joinsMysql joins
Mysql joins
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 
set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
 
Beginers guide for oracle sql
Beginers guide for oracle sqlBeginers guide for oracle sql
Beginers guide for oracle sql
 
Structured query language(sql)ppt
Structured query language(sql)pptStructured query language(sql)ppt
Structured query language(sql)ppt
 

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
 
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
 
Class XII-UNIT III - SQL and MySQL Notes_0.pdf
Class XII-UNIT III - SQL and MySQL Notes_0.pdfClass XII-UNIT III - SQL and MySQL Notes_0.pdf
Class XII-UNIT III - SQL and MySQL Notes_0.pdf
 
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

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 

Dernier (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 

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');