SlideShare a Scribd company logo
1 of 8
Download to read offline
Five
Common
SQL Errors
academy.vertabelo.com
As you learn SQL, watch out for these
common coding mistakes
You’ve written some SQL code and you’re ready
to query your database.
You input the code and …. no data is returned.
Instead, you get an error message.
Don’t despair! Coding errors are common in any
programming language, and SQL is no exception.
In this post, we’ll discuss five common mistakes
people make when writing SQL.
The most common SQL error is a syntax error.
Syntax: A set arrangement of words and commands.
People tend to make the same kinds of syntax mistakes.
Knowing what errors to look for is very important for
novice SQL coders.
The SQL errors we will look at are:
Misspelling Commands
Forgetting Brackets and Quotes
Specifying an Invalid Statement Order
Omitting Table Aliases
Using Case-Sensitive Names
1
2
3
4
5
Watch Your Language (and Syntax)
1. Misspelling Commands
This is the most common type of mistake. Example:
If you run this query, you’ll get an error which states:
Misspelling FROM as FORM.
Misspellings are found in keywords (like SELECT,
FROM, and WHERE), or in table and column names.
Most SQL spelling errors are due to:
“Chubby fingers” hitting a letter near the right one:
SELEVT or FTOM
“Reckless typing” typing the correct letters in the
wrong order: SELETC or FORM
SELECT *
FORM dish
WHERE NAME = ’Prawn Salad’;
Syntax error in SQL statement ”SELECT * FORM[*] dish
WHERE NAME = ’Prawn Salad’;”;
SQL statement: SELECT * FORM dish WHERE NAME = ’Prawn
Salad’; [42000-176]
Solution:
The editor puts SELECT statement keyword in light
purple. If the keyword is black you know there’s a
problem (FORM is black). Correct statement is:
The keyword is now the right color, the statement
executes without an error.
SELECT *
FROM dish
WHERE NAME = ’Prawn Salad’
SELECT *
FROM artist
WHERE first_name = ’Vincent’ and
last_name = ’Monet’ or last_name =
’Da Vinci’;
SELECT *
FROM artist
WHERE first_name = ’Vincent’ and
(last_name = ’Monet’ or last_name =
’Da Vinci’);
2. Forgetting Brackets and Quotes
Brackets group operations together. In SQL,
the following order of operations...
… is not the same as:
A common mistake is to forget the closing bracket.
This statement:
returns an error :
Remember: brackets always come in pairs.
The same is true with quotes (‘ ‘ and ” ”).
SELECT *
FROM artist
WHERE first_name = ’Vincent’ and
(last_name = ’Monet’ or last_name =
’Da Vinci’;
ERROR: syntax error at or near ”;” Position: 102
Solution:
Getmoreexperienceandrememberpeopleusuallyforget
the closing, not the opening, bracket or quotation mark.
ORDER BY sets the order in which the results will
be displayed
Invalid order like this one:
3. Invalid statement order
SELECT statements have a predefined keyword order.
A correctly-ordered SELECT statement:
SELECT name
FROM dish
WHERE name = ’Prawn Salad’
GROUP BY name
HAVING count(*) = 1
ORDER BY name;
There’s no shortcut here; you simply have to remember
the correct keyword order for the SELECT statement:
SELECT identifies column names and functions
FROM specifies table name or names (and JOIN
conditions)
WHERE defines filtering statements
GROUP BY shows how to group columns
HAVING filters the grouped values
SELECT name
FROM dish
WHERE name = ’Prawn Salad’
ORDER BY name
GROUP BY name
HAVING count(*) = 1
The error message we see is pretty intimidating!
Syntax error in SQL statement ”SELECT name FROM dish
WHERE name = ’Prawn Salad’ ORDER BY name GROUP[*] BY
name HAVING count(*) = 1;”; SQL statement:
SELECT name FROM dish WHERE name = ’Prawn Salad’ ORDER
BY name GROUP BY name HAVING count(*) = 1; [42000-176]
Solution:
I suggest using a short SELECT order checklist. Refer to
your list for the correct order and practice.
1
2
3
4
5
6
4. Omitting Table Aliases
Aliases distinguish among columns with the same name
acrosstables.
Aliasesaremandatoryifwejoinatabletoitself.
ThisSELECTstatement:
Returns an error:
SELECT *
FROM exhibit
JOIN exhibit ON (id = previous_id);
Ambiguous column name ”id”; SQL statement: SELECT
* FROM exhibit JOIN exhibit ON (id = previous_id);
[90059-176]
Note: When you get “ambiguous column name” error
message, you need table aliases.
The correct statement, with aliases, is:
SELECT ex.* , exp.name
FROM exhibit
JOIN exhibit ON (ex.id = exp.previous_id);
Solution:
Practice using table aliases for single-table SELECT
statements.
Usealiasesoften–theymakeyourSQLmorereadable.
5. Using Case-Sensitive Names
Object names in databases are case-insensitive. This
error occurs when you write non-standard names for
tables or database objects. To correct errors tied to this
use double quotes on table name. For example:
You will need to use double quotes when:
The table will have a case-sensitive name.
The table name will contain special characters. This
includes using a blank space, like “Large Client”.
SELECT * FROM
”LargeClient”
WHERE cust_name = ’Mijona’;
Solution:
Avoid using non-standard names if you can. If not,
remember your double quotes!
Everybody Makes SQL Mistakes
Making mistakes is a normal and predictable part
of  oftware development.
Don’t be discouraged.
When you make mistakes, try to analyze your code in
a structured way.
With a structured analysis, you can find and correct
your errors quicker.
Aldo Zelen
Find out more SQL topics on
academy.vertabelo.com/blog

More Related Content

What's hot

Project Fusion Reference Guide V2
Project Fusion Reference Guide V2Project Fusion Reference Guide V2
Project Fusion Reference Guide V2dnmiller
 
Optiva-13449_TestResults
Optiva-13449_TestResultsOptiva-13449_TestResults
Optiva-13449_TestResultsHarvey Canaan
 
Database Management - Lecture 3 - SQL Aggregate Functions, Join
Database Management - Lecture 3 - SQL Aggregate Functions, JoinDatabase Management - Lecture 3 - SQL Aggregate Functions, Join
Database Management - Lecture 3 - SQL Aggregate Functions, JoinAl-Mamun Sarkar
 
PHP 7.x - past, present, future
PHP 7.x - past, present, futurePHP 7.x - past, present, future
PHP 7.x - past, present, futureBoyan Yordanov
 
PHP 7.x - past, present, future (WordPress Varna #4)
PHP 7.x - past, present, future (WordPress Varna #4)PHP 7.x - past, present, future (WordPress Varna #4)
PHP 7.x - past, present, future (WordPress Varna #4)Boyan Yordanov
 
7 reasons why developers should love Joomla!
7 reasons why developers should love Joomla!7 reasons why developers should love Joomla!
7 reasons why developers should love Joomla!Bartłomiej Krztuk
 
Report alephcollection code_call_no_order
Report alephcollection code_call_no_orderReport alephcollection code_call_no_order
Report alephcollection code_call_no_orderjanette_rozene
 

What's hot (12)

Project Fusion Reference Guide V2
Project Fusion Reference Guide V2Project Fusion Reference Guide V2
Project Fusion Reference Guide V2
 
Exportrows
ExportrowsExportrows
Exportrows
 
Duplicaterows
DuplicaterowsDuplicaterows
Duplicaterows
 
Optiva-13449_TestResults
Optiva-13449_TestResultsOptiva-13449_TestResults
Optiva-13449_TestResults
 
Database Management - Lecture 3 - SQL Aggregate Functions, Join
Database Management - Lecture 3 - SQL Aggregate Functions, JoinDatabase Management - Lecture 3 - SQL Aggregate Functions, Join
Database Management - Lecture 3 - SQL Aggregate Functions, Join
 
PHP 7.x - past, present, future
PHP 7.x - past, present, futurePHP 7.x - past, present, future
PHP 7.x - past, present, future
 
Pl sql using_xml
Pl sql using_xmlPl sql using_xml
Pl sql using_xml
 
PHP 7.x - past, present, future (WordPress Varna #4)
PHP 7.x - past, present, future (WordPress Varna #4)PHP 7.x - past, present, future (WordPress Varna #4)
PHP 7.x - past, present, future (WordPress Varna #4)
 
7 reasons why developers should love Joomla!
7 reasons why developers should love Joomla!7 reasons why developers should love Joomla!
7 reasons why developers should love Joomla!
 
Project2q
Project2qProject2q
Project2q
 
Report alephcollection code_call_no_order
Report alephcollection code_call_no_orderReport alephcollection code_call_no_order
Report alephcollection code_call_no_order
 
Les11
Les11Les11
Les11
 

Viewers also liked

Paraguay | Jul-16 | Future technology options and productive use
Paraguay | Jul-16 | Future technology options and productive useParaguay | Jul-16 | Future technology options and productive use
Paraguay | Jul-16 | Future technology options and productive useSmart Villages
 
สตอเบอรรี่ ครบสูตรคุณประโยชน์เพื่อสุขภาพ
สตอเบอรรี่ ครบสูตรคุณประโยชน์เพื่อสุขภาพสตอเบอรรี่ ครบสูตรคุณประโยชน์เพื่อสุขภาพ
สตอเบอรรี่ ครบสูตรคุณประโยชน์เพื่อสุขภาพnattanit yuyuenyong
 
Operational Risk Debt ReductionOpEd
Operational Risk Debt ReductionOpEdOperational Risk Debt ReductionOpEd
Operational Risk Debt ReductionOpEdRupert Brown
 
福建武夷山
福建武夷山福建武夷山
福建武夷山Su Kong
 
AIA101.4.Automating Access
AIA101.4.Automating AccessAIA101.4.Automating Access
AIA101.4.Automating AccessDan D'Urso
 
Portafolio fisica terminado1p
Portafolio fisica terminado1pPortafolio fisica terminado1p
Portafolio fisica terminado1porly Fernandez
 
Chapter 6 report (MS Access)
Chapter 6 report (MS Access)Chapter 6 report (MS Access)
Chapter 6 report (MS Access)Keiotic
 
Presentazione G55 - Coworking/Fablab Partanna
Presentazione G55 - Coworking/Fablab PartannaPresentazione G55 - Coworking/Fablab Partanna
Presentazione G55 - Coworking/Fablab PartannaAntonino Zinnanti
 
Chuchura Aroggyo Final Round 2017
Chuchura Aroggyo Final Round  2017Chuchura Aroggyo Final Round  2017
Chuchura Aroggyo Final Round 2017SAIKAT BANIK(FQC)
 
Sanghati Utsav Final Round 2016
Sanghati Utsav Final Round  2016Sanghati Utsav Final Round  2016
Sanghati Utsav Final Round 2016SAIKAT BANIK(FQC)
 
What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great InfographicsSlideShare
 
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareEmpowered Presentations
 
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingHow To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingContent Marketing Institute
 
Masters of SlideShare
Masters of SlideShareMasters of SlideShare
Masters of SlideShareKapost
 
10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation OptimizationOneupweb
 

Viewers also liked (20)

Why Should I learn SQL?
Why Should I learn SQL?Why Should I learn SQL?
Why Should I learn SQL?
 
7462 slideshare ala
7462 slideshare ala7462 slideshare ala
7462 slideshare ala
 
Paraguay | Jul-16 | Future technology options and productive use
Paraguay | Jul-16 | Future technology options and productive useParaguay | Jul-16 | Future technology options and productive use
Paraguay | Jul-16 | Future technology options and productive use
 
[NCS 기반 채용] 핵심 파해치기
 [NCS 기반 채용] 핵심 파해치기  [NCS 기반 채용] 핵심 파해치기
[NCS 기반 채용] 핵심 파해치기
 
สตอเบอรรี่ ครบสูตรคุณประโยชน์เพื่อสุขภาพ
สตอเบอรรี่ ครบสูตรคุณประโยชน์เพื่อสุขภาพสตอเบอรรี่ ครบสูตรคุณประโยชน์เพื่อสุขภาพ
สตอเบอรรี่ ครบสูตรคุณประโยชน์เพื่อสุขภาพ
 
Operational Risk Debt ReductionOpEd
Operational Risk Debt ReductionOpEdOperational Risk Debt ReductionOpEd
Operational Risk Debt ReductionOpEd
 
Hcd
HcdHcd
Hcd
 
福建武夷山
福建武夷山福建武夷山
福建武夷山
 
AIA101.4.Automating Access
AIA101.4.Automating AccessAIA101.4.Automating Access
AIA101.4.Automating Access
 
Portafolio fisica terminado1p
Portafolio fisica terminado1pPortafolio fisica terminado1p
Portafolio fisica terminado1p
 
Chapter 6 report (MS Access)
Chapter 6 report (MS Access)Chapter 6 report (MS Access)
Chapter 6 report (MS Access)
 
Presentazione G55 - Coworking/Fablab Partanna
Presentazione G55 - Coworking/Fablab PartannaPresentazione G55 - Coworking/Fablab Partanna
Presentazione G55 - Coworking/Fablab Partanna
 
Chuchura Aroggyo Final Round 2017
Chuchura Aroggyo Final Round  2017Chuchura Aroggyo Final Round  2017
Chuchura Aroggyo Final Round 2017
 
Sanghati Utsav Final Round 2016
Sanghati Utsav Final Round  2016Sanghati Utsav Final Round  2016
Sanghati Utsav Final Round 2016
 
What Makes Great Infographics
What Makes Great InfographicsWhat Makes Great Infographics
What Makes Great Infographics
 
You Suck At PowerPoint!
You Suck At PowerPoint!You Suck At PowerPoint!
You Suck At PowerPoint!
 
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to SlideshareSTOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
STOP! VIEW THIS! 10-Step Checklist When Uploading to Slideshare
 
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content MarketingHow To Get More From SlideShare - Super-Simple Tips For Content Marketing
How To Get More From SlideShare - Super-Simple Tips For Content Marketing
 
Masters of SlideShare
Masters of SlideShareMasters of SlideShare
Masters of SlideShare
 
10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization10 Ways to Win at SlideShare SEO & Presentation Optimization
10 Ways to Win at SlideShare SEO & Presentation Optimization
 

Similar to Five Common SQL Errors

Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic ConceptsTony Wong
 
MYSQL
MYSQLMYSQL
MYSQLARJUN
 
Advanced SQL Injection
Advanced SQL InjectionAdvanced SQL Injection
Advanced SQL Injectionamiable_indian
 
Sql Injection Adv Owasp
Sql Injection Adv OwaspSql Injection Adv Owasp
Sql Injection Adv OwaspAung Khant
 
RDBMS Lab03 applying constraints (UIU)
RDBMS Lab03 applying constraints (UIU)RDBMS Lab03 applying constraints (UIU)
RDBMS Lab03 applying constraints (UIU)Muhammad T Q Nafis
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standardsAlessandro Baratella
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commandsBelle Wx
 
Exploring collections with example
Exploring collections with exampleExploring collections with example
Exploring collections with examplepranav kumar verma
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraintsVivek Singh
 
Dynamic websites(lec1)
Dynamic websites(lec1)Dynamic websites(lec1)
Dynamic websites(lec1)Belal Arfa
 
45 Essential SQL Interview Questions
45 Essential SQL Interview Questions45 Essential SQL Interview Questions
45 Essential SQL Interview QuestionsBest SEO Tampa
 

Similar to Five Common SQL Errors (20)

Hira
HiraHira
Hira
 
SQL -PHP Tutorial
SQL -PHP TutorialSQL -PHP Tutorial
SQL -PHP Tutorial
 
Database Architecture and Basic Concepts
Database Architecture and Basic ConceptsDatabase Architecture and Basic Concepts
Database Architecture and Basic Concepts
 
MYSQL
MYSQLMYSQL
MYSQL
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
 
Advanced SQL Injection
Advanced SQL InjectionAdvanced SQL Injection
Advanced SQL Injection
 
Sql Injection Adv Owasp
Sql Injection Adv OwaspSql Injection Adv Owasp
Sql Injection Adv Owasp
 
RDBMS Lab03 applying constraints (UIU)
RDBMS Lab03 applying constraints (UIU)RDBMS Lab03 applying constraints (UIU)
RDBMS Lab03 applying constraints (UIU)
 
SQL report
SQL reportSQL report
SQL report
 
SQL PPT.pptx
SQL PPT.pptxSQL PPT.pptx
SQL PPT.pptx
 
Database development coding standards
Database development coding standardsDatabase development coding standards
Database development coding standards
 
Sql basics
Sql  basicsSql  basics
Sql basics
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Exploring collections with example
Exploring collections with exampleExploring collections with example
Exploring collections with example
 
Sql
SqlSql
Sql
 
Sql Injection
Sql Injection Sql Injection
Sql Injection
 
Sql integrity constraints
Sql integrity constraintsSql integrity constraints
Sql integrity constraints
 
Chapter08
Chapter08Chapter08
Chapter08
 
Dynamic websites(lec1)
Dynamic websites(lec1)Dynamic websites(lec1)
Dynamic websites(lec1)
 
45 Essential SQL Interview Questions
45 Essential SQL Interview Questions45 Essential SQL Interview Questions
45 Essential SQL Interview Questions
 

Recently uploaded

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 

Recently uploaded (20)

Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 

Five Common SQL Errors

  • 1. Five Common SQL Errors academy.vertabelo.com As you learn SQL, watch out for these common coding mistakes
  • 2. You’ve written some SQL code and you’re ready to query your database. You input the code and …. no data is returned. Instead, you get an error message. Don’t despair! Coding errors are common in any programming language, and SQL is no exception. In this post, we’ll discuss five common mistakes people make when writing SQL.
  • 3. The most common SQL error is a syntax error. Syntax: A set arrangement of words and commands. People tend to make the same kinds of syntax mistakes. Knowing what errors to look for is very important for novice SQL coders. The SQL errors we will look at are: Misspelling Commands Forgetting Brackets and Quotes Specifying an Invalid Statement Order Omitting Table Aliases Using Case-Sensitive Names 1 2 3 4 5 Watch Your Language (and Syntax)
  • 4. 1. Misspelling Commands This is the most common type of mistake. Example: If you run this query, you’ll get an error which states: Misspelling FROM as FORM. Misspellings are found in keywords (like SELECT, FROM, and WHERE), or in table and column names. Most SQL spelling errors are due to: “Chubby fingers” hitting a letter near the right one: SELEVT or FTOM “Reckless typing” typing the correct letters in the wrong order: SELETC or FORM SELECT * FORM dish WHERE NAME = ’Prawn Salad’; Syntax error in SQL statement ”SELECT * FORM[*] dish WHERE NAME = ’Prawn Salad’;”; SQL statement: SELECT * FORM dish WHERE NAME = ’Prawn Salad’; [42000-176] Solution: The editor puts SELECT statement keyword in light purple. If the keyword is black you know there’s a problem (FORM is black). Correct statement is: The keyword is now the right color, the statement executes without an error. SELECT * FROM dish WHERE NAME = ’Prawn Salad’
  • 5. SELECT * FROM artist WHERE first_name = ’Vincent’ and last_name = ’Monet’ or last_name = ’Da Vinci’; SELECT * FROM artist WHERE first_name = ’Vincent’ and (last_name = ’Monet’ or last_name = ’Da Vinci’); 2. Forgetting Brackets and Quotes Brackets group operations together. In SQL, the following order of operations... … is not the same as: A common mistake is to forget the closing bracket. This statement: returns an error : Remember: brackets always come in pairs. The same is true with quotes (‘ ‘ and ” ”). SELECT * FROM artist WHERE first_name = ’Vincent’ and (last_name = ’Monet’ or last_name = ’Da Vinci’; ERROR: syntax error at or near ”;” Position: 102 Solution: Getmoreexperienceandrememberpeopleusuallyforget the closing, not the opening, bracket or quotation mark.
  • 6. ORDER BY sets the order in which the results will be displayed Invalid order like this one: 3. Invalid statement order SELECT statements have a predefined keyword order. A correctly-ordered SELECT statement: SELECT name FROM dish WHERE name = ’Prawn Salad’ GROUP BY name HAVING count(*) = 1 ORDER BY name; There’s no shortcut here; you simply have to remember the correct keyword order for the SELECT statement: SELECT identifies column names and functions FROM specifies table name or names (and JOIN conditions) WHERE defines filtering statements GROUP BY shows how to group columns HAVING filters the grouped values SELECT name FROM dish WHERE name = ’Prawn Salad’ ORDER BY name GROUP BY name HAVING count(*) = 1 The error message we see is pretty intimidating! Syntax error in SQL statement ”SELECT name FROM dish WHERE name = ’Prawn Salad’ ORDER BY name GROUP[*] BY name HAVING count(*) = 1;”; SQL statement: SELECT name FROM dish WHERE name = ’Prawn Salad’ ORDER BY name GROUP BY name HAVING count(*) = 1; [42000-176] Solution: I suggest using a short SELECT order checklist. Refer to your list for the correct order and practice. 1 2 3 4 5 6
  • 7. 4. Omitting Table Aliases Aliases distinguish among columns with the same name acrosstables. Aliasesaremandatoryifwejoinatabletoitself. ThisSELECTstatement: Returns an error: SELECT * FROM exhibit JOIN exhibit ON (id = previous_id); Ambiguous column name ”id”; SQL statement: SELECT * FROM exhibit JOIN exhibit ON (id = previous_id); [90059-176] Note: When you get “ambiguous column name” error message, you need table aliases. The correct statement, with aliases, is: SELECT ex.* , exp.name FROM exhibit JOIN exhibit ON (ex.id = exp.previous_id); Solution: Practice using table aliases for single-table SELECT statements. Usealiasesoften–theymakeyourSQLmorereadable.
  • 8. 5. Using Case-Sensitive Names Object names in databases are case-insensitive. This error occurs when you write non-standard names for tables or database objects. To correct errors tied to this use double quotes on table name. For example: You will need to use double quotes when: The table will have a case-sensitive name. The table name will contain special characters. This includes using a blank space, like “Large Client”. SELECT * FROM ”LargeClient” WHERE cust_name = ’Mijona’; Solution: Avoid using non-standard names if you can. If not, remember your double quotes! Everybody Makes SQL Mistakes Making mistakes is a normal and predictable part of  oftware development. Don’t be discouraged. When you make mistakes, try to analyze your code in a structured way. With a structured analysis, you can find and correct your errors quicker. Aldo Zelen Find out more SQL topics on academy.vertabelo.com/blog