You are on page 1of 3

SQL:

SQL stands for Structured Query Language.SQL is a standard language for accessin
g and manipulating databases.
A database most often contains one or more tables. Each table is identified by a
name (e.g. "Customers" or "Orders").
Tables contain records (rows) with data.
Some of The Most Important SQL Commands
SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database
CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index
===============================
SELECT :
--------SELECT column_name,column_name
FROM table_name;
SELECT * FROM table_name;
The SELECT DISTINCT statement is used to return only distinct (different) values
.
-------------------------------------------------------------------------------SELECT DISTINCT column_name,column_name
FROM table_name;
The WHERE clause is used to filter records.
---------------------------------SELECT column_name,column_name
FROM table_name
WHERE column_name operator value;
Operator
Description
-------------------------------=
Equal
<>
Not equal. Note: In some versions of SQL this operator may be written as
!=
>
Greater than
<
Less than
>=
Greater than or equal
<=
Less than or equal
BETWEEN Between an inclusive range
LIKE
Search for a pattern
IN
To specify multiple possible values for a column
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
--------------------------------------------------------

The ORDER BY keyword is used to sort the result-set one or more columns..The ORD
ER BY keyword sorts the records in ascending order by default.
To sort the records in a descending order, you can use the DESC keyword.
----------------------------------------------------SELECT column_name,column_name
FROM table_name
ORDER BY column_name,column_name ASC|DESC;
=========================================================
The INSERT INTO statement is used to insert new records in a table.
------------------------------------------------------------INSERT INTO table_name
VALUES (value1,value2,value3,...);
INSERT INTO table_name (column1,column2,column3,...)
VALUES (value1,value2,value3,...);
=======================================================================
The UPDATE statement is used to update existing records in a table.
-------------------------------------------------------------------UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;
==========================================================================
The DELETE statement is used to delete records in a table.
---------------------------------------------------------DELETE FROM table_name
WHERE some_column=some_value;
================================================================================
==
SQL aliases are used to temporarily rename a table or a column heading.
SELECT column_name AS alias_name
FROM table_name;
SELECT column_name(s)
FROM table_name AS alias_name;
================================================================================
=======
SQL joins are used to combine rows from two or more tables.
the types the different SQL JOINs you can use:
INNER JOIN: Returns all rows when there is at least one match in BOTH tables
LEFT JOIN: Return all rows from the left table, and the matched rows from the ri
ght table
RIGHT JOIN: Return all rows from the right table, and the matched rows from the
left table
FULL JOIN: Return all rows when there is a match in ONE of the tables

The INNER JOIN keyword selects all rows from both tables as long as there is a m
atch between the columns in both tables.
SELECT column_name(s)

FROM table1
INNER JOIN table2
ON table1.column_name=table2.column_name;

or:
SELECT column_name(s)
FROM table1
JOIN table2
ON table1.column_name=table2.column_name;
--------------------------------------------------------------The LEFT JOIN keyword returns all rows from the left table (table1), with the ma
tching rows in the right table (table2). The result is NULL in the right side wh
en there is no match.
SQL LEFT JOIN Syntax
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name=table2.column_name;
------------------------------------------------------------The RIGHT JOIN keyword returns all rows from the right table (table2), with the
matching rows in the left table (table1). The result is NULL in the left side wh
en there is no match.
SQL RIGHT JOIN Syntax
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name=table2.column_name;
--------------------------------------------------------------------The FULL OUTER JOIN keyword returns all rows from the left table (table1) and fr
om the right table (table2).
The FULL OUTER JOIN keyword combines the result of both LEFT and RIGHT joins.
SQL FULL OUTER JOIN Syntax
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name=table2.column_name;

You might also like