{"id":75,"date":"2018-12-05T08:39:11","date_gmt":"2018-12-05T08:39:11","guid":{"rendered":"https:\/\/barkhane.com\/sql\/2018\/12\/05\/sql-syntax\/"},"modified":"2024-03-03T18:09:07","modified_gmt":"2024-03-03T18:09:07","slug":"sql-syntax","status":"publish","type":"post","link":"https:\/\/barkhane.com\/sql\/sql-syntax\/","title":{"rendered":"SQL &#8211; Syntax"},"content":{"rendered":"<p>SQL \u2013 Syntax: The syntax of SQL is governed by the American National Standards Institute (ANSI) and the International Organization for Standardization (ISO).<\/p>\n<blockquote>\n<h2>SQL Statements<\/h2>\n<ul>\n<li>SQL statements are very simple and straightforward like plain English but with specific syntax.<\/li>\n<li>An SQL statement is composed of a sequence of keywords, identifiers, etc. terminated by a semicolon (;). Some database systems require a semicolon at the end of each SQL statement. Semicolon is the standard way to separate each SQL statement in database systems that allow more than one SQL statement to be executed in the same call to the server.<\/li>\n<li><b>SQL<\/b>\u00a0is not case sensitive. Generally SQL keywords are written in uppercase.<\/li>\n<\/ul>\n<\/blockquote>\n<h2>Various Syntax in SQL<\/h2>\n<blockquote><p>All the examples given in this tutorial have been tested with a MySQL server.<\/p><\/blockquote>\n<h3>SQL SELECT Statement<\/h3>\n<pre class=\"result notranslate\">SELECT column1, column2....columnN\nFROM   table_name;\n<\/pre>\n<h3>SQL DISTINCT Clause<\/h3>\n<pre class=\"result notranslate\">SELECT DISTINCT column1, column2....columnN\nFROM   table_name;\n<\/pre>\n<h3>SQL WHERE Clause<\/h3>\n<pre class=\"result notranslate\">SELECT column1, column2....columnN\nFROM   table_name\nWHERE  CONDITION;\n<\/pre>\n<h3>SQL AND\/OR Clause<\/h3>\n<pre class=\"result notranslate\">SELECT column1, column2....columnN\nFROM   table_name\nWHERE  CONDITION-1 {AND|OR} CONDITION-2;\n<\/pre>\n<h3>SQL IN Clause<\/h3>\n<pre class=\"result notranslate\">SELECT column1, column2....columnN\nFROM   table_name\nWHERE  column_name IN (val-1, val-2,...val-N);\n<\/pre>\n<h3>SQL BETWEEN Clause<\/h3>\n<pre class=\"result notranslate\">SELECT column1, column2....columnN\nFROM   table_name\nWHERE  column_name BETWEEN val-1 AND val-2;\n<\/pre>\n<h3>SQL LIKE Clause<\/h3>\n<pre class=\"result notranslate\">SELECT column1, column2....columnN\nFROM   table_name\nWHERE  column_name LIKE { PATTERN };\n<\/pre>\n<h3>SQL ORDER BY Clause<\/h3>\n<pre class=\"result notranslate\">SELECT column1, column2....columnN\nFROM   table_name\nWHERE  CONDITION\nORDER BY column_name {ASC|DESC};\n<\/pre>\n<h3>SQL GROUP BY Clause<\/h3>\n<pre class=\"result notranslate\">SELECT SUM(column_name)\nFROM   table_name\nWHERE  CONDITION\nGROUP BY column_name;\n<\/pre>\n<h3>SQL COUNT Clause<\/h3>\n<pre class=\"result notranslate\">SELECT COUNT(column_name)\nFROM   table_name\nWHERE  CONDITION;\n<\/pre>\n<h3>SQL HAVING Clause<\/h3>\n<pre class=\"result notranslate\">SELECT SUM(column_name)\nFROM   table_name\nWHERE  CONDITION\nGROUP BY column_name\nHAVING (arithematic function condition);\n<\/pre>\n<h3>SQL CREATE TABLE Statement<\/h3>\n<pre class=\"result notranslate\">CREATE TABLE table_name(\ncolumn1 datatype,\ncolumn2 datatype,\ncolumn3 datatype,\n.....\ncolumnN datatype,\nPRIMARY KEY( one or more columns )\n);\n<\/pre>\n<h3>SQL DROP TABLE Statement<\/h3>\n<pre class=\"result notranslate\">DROP TABLE table_name;\n<\/pre>\n<h3>SQL CREATE INDEX Statement<\/h3>\n<pre class=\"result notranslate\">CREATE UNIQUE INDEX index_name\nON table_name ( column1, column2,...columnN);\n<\/pre>\n<h3>SQL DROP INDEX Statement<\/h3>\n<pre class=\"result notranslate\">ALTER TABLE table_name\nDROP INDEX index_name;\n<\/pre>\n<h3>SQL DESC Statement<\/h3>\n<pre class=\"result notranslate\">DESC table_name;\n<\/pre>\n<h3>SQL TRUNCATE TABLE Statement<\/h3>\n<pre class=\"result notranslate\">TRUNCATE TABLE table_name;\n<\/pre>\n<h3>SQL ALTER TABLE Statement<\/h3>\n<pre class=\"result notranslate\">ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};\n<\/pre>\n<h3>SQL ALTER TABLE Statement (Rename)<\/h3>\n<pre class=\"result notranslate\">ALTER TABLE table_name RENAME TO new_table_name;\n<\/pre>\n<h3>SQL INSERT INTO Statement<\/h3>\n<pre class=\"result notranslate\">INSERT INTO table_name( column1, column2....columnN)\nVALUES ( value1, value2....valueN);\n<\/pre>\n<h3>SQL UPDATE Statement<\/h3>\n<pre class=\"result notranslate\">UPDATE table_name\nSET column1 = value1, column2 = value2....columnN=valueN\n[ WHERE  CONDITION ];\n<\/pre>\n<h3>SQL DELETE Statement<\/h3>\n<pre class=\"result notranslate\">DELETE FROM table_name\nWHERE  {CONDITION};\n<\/pre>\n<h3>SQL CREATE DATABASE Statement<\/h3>\n<pre class=\"result notranslate\">CREATE DATABASE database_name;\n<\/pre>\n<h3>SQL DROP DATABASE Statement<\/h3>\n<pre class=\"result notranslate\">DROP DATABASE database_name;\n<\/pre>\n<h3>SQL USE Statement<\/h3>\n<pre class=\"result notranslate\">USE database_name;\n<\/pre>\n<h3>SQL COMMIT Statement<\/h3>\n<pre class=\"result notranslate\">COMMIT;\n<\/pre>\n<h3>SQL ROLLBACK Statement<\/h3>\n<pre class=\"result notranslate\">ROLLBACK;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>SQL \u2013 Syntax: The syntax of SQL is governed by the American National Standards Institute (ANSI) and the International Organization [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[2],"tags":[],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/comments?post=75"}],"version-history":[{"count":0,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts\/75\/revisions"}],"wp:attachment":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/media?parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/categories?post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/tags?post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}