RDBMS
RDBMS
Rameswara Reddy.K.V
DDL (Data Definition Language)
Ex: commit;
Grant
Revoke
Max
sum
abs
sqrt
upper
length
ltrim
SELECT * FROM Customers
WHERE CustomerName LIKE '%a';
SELECT * FROM Customers
WHERE CustomerName LIKE '%or%';
SELECT * FROM Customers
WHERE CustomerName LIKE '_r%';
SELECT * FROM Customers
WHERE CustomerName LIKE 'a_ _%';
SELECT * FROM Customers
WHERE ContactName LIKE 'a%o';
SELECT * FROM Customers
WHERE CustomerName NOT LIKE 'a%';
In operator
The SQL IN Operator
The IN operator allows you to specify multiple values
in a WHERE clause.
The IN operator is a shorthand for multiple OR
conditions.
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
IN
Ex: SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');
Ex: SELECT * FROM Customers
WHERE Country NOT IN ('Germany', 'France', 'UK');
Ex: SELECT * FROM Customers
WHERE Country IN (SELECT Country FROM Supplie
rs);
Range Search:
Between & Not Between
The SQL BETWEEN Operator
The BETWEEN operator selects values within a given
range. The values can be numbers, text, or dates.
The BETWEEN operator is inclusive: begin and end
values are included.
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Ex: select empno,ename,job from emp where sal
between 1000 and 2000;
SELECT * FROM Customers
ORDER BY Country DESC;
SELECT * FROM Customers
ORDER BY Country ASC, CustomerName DESC;
Group by
The GROUP BY statement groups rows that have the
same values into summary rows, like "find the number of
customers in each country".
The GROUP BY statement is often used with aggregate
functions (COUNT, MAX, MIN, SUM, AVG) to group the
result-set by one or more columns.
SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country;
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
ORDER BY COUNT(CustomerID) DESC;
SQL Joins
A JOIN clause is used to combine rows from two or more tables, based
on a related column between them.
Different Types of SQL JOINs
Here are the different types of the JOINs in SQL:
(INNER) JOIN: Returns records that have matching values in both
tables
LEFT (OUTER) JOIN: Returns all records from the left table, and the
matched records from the right table
RIGHT (OUTER) JOIN: Returns all records from the right table, and
the matched records from the left table
FULL (OUTER) JOIN: Returns all records when there is a match in
either left or right table
INNER JOIN
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
Ex: SELECT Orders.OrderID,
Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID =
Customers.CustomerID;
LEFT JOIN
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
Ex: SELECT City FROM Customers
UNION ALL
SELECT City FROM Suppliers
ORDER BY City;
Intersect
The INTERSECT clause in SQL is used to combine
two SELECT statements but the dataset returned by
the INTERSECT statement will be the intersection of
the data-sets of the two SELECT statements.
In simple words, the INTERSECT statement will
return only those rows which will be common to both
of the SELECT statements.
SELECT column1 , column2 .... FROM table_names WHERE
condition INTERSECT SELECT column1 , column2 .... FROM
table_names WHERE condition