find and solve || findandsolve.com
Please wait.....

Syntax of SQL

A SQL database most often contains one or more tables . Tables contain records  with data. Each table is identified by a name example "EmployeeInfo"

A unique set of rules and guidelines called Syntax are applied to SQL. Our tutorial gives you a quick start with all SQL Syntax.

SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW are  the keywords all the SQL statements start usually and all the statements end with a semicolon (;).

The SQL is case insensitive, which means SELECT and select have same meaning in SQL statements. Whereas, MySQL makes difference in table names.


SQL SELECT Statement

SELECT col1, col2....colN FROM table_name;

where,

col1=column1

table_name=name of the table used to query the data


SQL DISTINCT Clause

SELECT DISTINCT col1, col2....colN FROM   table_name;


SQL WHERE Clause

SELECT col1, col2....colN FROM   table_name WHERE  CONDITION;


SQL AND/OR Clause

SELECT col1, col2....colN FROM   table_name WHERE  CONDITION-1 {AND|OR} CONDITION-2;


SQL IN Clause

SELECT col1, col2....colN FROM  table_name WHERE  column_name IN (val1, val2,...valN);


SQL BETWEEN Clause

SELECT col1, col2....colN FROM table_name WHERE  column_name BETWEEN val1 AND val2; 



SQL LIKE Clause

SELECT col1, col2....colN FROM table_name WHERE  column_name LIKE { PATTERN }; 


SQL ORDER BY Clause

SELECT col1, col2....colN FROM   table_name WHERE  CONDITION ORDER BY column_name {ASC|DESC};


SQL GROUP BY Clause

SELECT SUM(column_name) FROM   table_name WHERE  CONDITION GROUP BY column_name;


SQL COUNT Clause

SELECT COUNT(column_name) FROM   table_name WHERE  CONDITION;


SQL HAVING Clause

SELECT SUM(column_name) FROM   table_name WHERE  CONDITION GROUP BY column_name HAVING (arithematic condition);


CREATE TABLE Statement

CREATE TABLE table_name(

col1 datatype,
col2 datatype,
col3 datatype,
.....
colN datatype,
Primary Key( one or more columns )
);


SQL DROP TABLE Statement

DROP TABLE table_name;


SQL TRUNCATE TABLE Statement

TRUNCATE TABLE table_name;


SQL ALTER TABLE Statement

ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};