0% found this document useful (0 votes)
25 views2 pages

SQL 1

The document lists and describes some of the most important SQL commands, including SELECT, UPDATE, DELETE, and INSERT for manipulating data, and CREATE DATABASE, ALTER DATABASE, CREATE TABLE, and ALTER TABLE for managing database structure. It also covers the WHERE clause and its operators (AND, OR, NOT) for filtering query results, and the ORDER BY clause for sorting query output in ascending or descending order.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

SQL 1

The document lists and describes some of the most important SQL commands, including SELECT, UPDATE, DELETE, and INSERT for manipulating data, and CREATE DATABASE, ALTER DATABASE, CREATE TABLE, and ALTER TABLE for managing database structure. It also covers the WHERE clause and its operators (AND, OR, NOT) for filtering query results, and the ORDER BY clause for sorting query output in ascending or descending order.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

SQL

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.

1. The SELECT DISTINCT statement is used to eliminate duplicate rows and display a unique list of values.

SELECT DISTINCT column1, column2, ... FROM table_name;

2. Select statement

SELECT column1, column2, ... FROM table_name;

3. Select Where statement. It is used to extract only those records that fulfil a specified condition.

SELECT column1, column2, ... FROM table_name WHERE condition

Ex  SELECT * FROM Customers WHERE Country='Mexico';

4. The WHERE clause can be combined with AND, OR, and NOT operators.

The AND and OR operators are used to filter records based on more than one condition:

 The AND operator displays a record if all the conditions separated by AND are TRUE.


 The OR operator displays a record if any of the conditions separated by OR is TRUE.
 The NOT operator displays a record if the condition(s) is NOT TRUE.

AND Syntax

SELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2 AND condition3 ...;

Ex  SELECT * FROM Customers WHERE Country='Germany' AND City='Berlin';

OR Syntax

SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2 OR condition3 ...;

Ex  SELECT * FROM Customers WHERE City='Berlin' OR City='München';

NOT Syntax

SELECT column1, column2, ... FROM table_name WHERE NOT condition;

Ex  SELECT * FROM Customers WHERE NOT Country='Germany';

You can also combine the AND, OR and NOT operators.

Ex  SELECT * FROM Customers WHERE Country='Germany' AND (City='Berlin' OR City='München');

Ex  SELECT * FROM Customers WHERE NOT Country='Germany' AND NOT Country='USA';
5. Order By statement used to sort the result-set in ascending or descending order.

Ex  SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC|DESC;

Ex  SELECT * FROM Customers ORDER BY Country;

Ex  SELECT * FROM Customers ORDER BY Country DESC;

Ex  SELECT * FROM Customers ORDER BY Country, CustomerName;

Ex  SELECT * FROM Customers ORDER BY Country ASC, CustomerName DESC;

You might also like