Basic SQL commands cane be classified in following groups based on their nature:
1. Data Definition Language (DDL)
2. Data Manipulation Language (DML)
3. Data Control Language (DCL)
4. Data Query Language (DQL)
SELECT: retrieves certain records from one or more tables
1. WHERE clause
It is used to specify a condition while fetching data from single table or multiple tables. WHERE clause is used with SELECT, UPDATE & DELETE statements.
Basic Syntax:
SELECT col_1 col_2
FROM table_name
WHERE <condition>
Condition can be specified using comparison or logical operators like >, <, =, NOT, LIKE etc.
2. LIKE clause
It is used to compare a value to similar values using wildcard operators. There are 2 wildcards used in conjunction with LIKE operator:
Percent sign (%) - represents zero, one or multiple characters
Underscore ( _ ) - represents a single number or character
Basic Syntax:
SELECT from table_name
WHERE column LIKE ' %xxx% '
and
SELECT from table_name
WHERE column LIKE ' _xxx_ '
3. TOP clause
It is used to fetch TOP N numbers or X percents records from a table. All the databases do not support TOP clause. MySQL uses LIMIT to fetch limited number of records and Oracle uses ROWNUM to produces similar results.
Basic Syntax:
SELECT TOP number|percent col_name
FROM table_name
WHERE <condition>
e.g. SELECT TOP 3 * FROM employee - this would fetch first 3 rows with all columns from employee table
4. ORDER BY Clause
It is used to sort the data in ascending or descending order, based on one or more columns. Usually ascending order is chosen by default.
Basic Syntax:
SELECT * from Employee
ORDER BY salary DESC;
5. GROUP BY Clause
It is used in combination with SELECT statement to arrange identical data into groups. It follows the WHERE clause and precedes the ORDER BY clause.
Basic Syntax:
SELECT col_1 col_2
FROM table_name
WHERE <condition>
GROUP BY col_1 col_2
ORDER BY col_1
6. HAVING Clause
It enables you to specify conditions that filter which group results appear in final results. WHERE clause places conditions on selected columns but HAVING clause places conditions on groups created by GROUP BY clause.
Basic Syntax:
SELECT col1, col2
FROM tab1, tab2
WHERE <conditions>
GROUP BY col1, col2
HAVING <conditions>
ORDER BY col1, col2
Transactions are sequences of work accomplished in logical order whether manually or by a database automatically.
All the transactions should maintain following properties/achieve following ends after occurring:
Following transaction control statements are used in SQL:
1. COMMIT command
2. ROLLBACK command
3. SAVEPOINT command
4. RELEASE_SAVEPOINT command
5. SET TRANSACTION command
536 videos|683 docs|263 tests
|
536 videos|683 docs|263 tests
|
|
Explore Courses for Bank Exams exam
|