SlideShare una empresa de Scribd logo
1 de 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');

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Basic sql Commands
Basic sql CommandsBasic sql Commands
Basic sql Commands
 
Sql(structured query language)
Sql(structured query language)Sql(structured query language)
Sql(structured query language)
 
SQL
SQLSQL
SQL
 
Aggregate function
Aggregate functionAggregate function
Aggregate function
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
 
SQL Joins and Query Optimization
SQL Joins and Query OptimizationSQL Joins and Query Optimization
SQL Joins and Query Optimization
 
Aggregate functions in SQL.pptx
Aggregate functions in SQL.pptxAggregate functions in SQL.pptx
Aggregate functions in SQL.pptx
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Sql clauses by Manan Pasricha
Sql clauses by Manan PasrichaSql clauses by Manan Pasricha
Sql clauses by Manan Pasricha
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
SQL select clause
SQL select clauseSQL select clause
SQL select clause
 
80 different SQL Queries with output
80 different SQL Queries with output80 different SQL Queries with output
80 different SQL Queries with output
 
Sql join
Sql  joinSql  join
Sql join
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
SQL - DML and DDL Commands
SQL - DML and DDL CommandsSQL - DML and DDL Commands
SQL - DML and DDL Commands
 
SQL
SQLSQL
SQL
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 

Destacado

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
 

Destacado (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
 

Similar a 06.01 sql select distinct

Similar a 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
 
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
 

Más 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
 

Más 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
 

Último

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 

Último (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 

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