Professional Documents
Culture Documents
Databases:
• Oracle SQL
• My SQL SQL
• DB2 SQL
• Hbase No-SQL
• Mongo DB No-SQL
A relational database, also called Relational Database Management System (RDBMS) or SQL
database, stores data in tables (i.e. structured format in rows and columns) and rows also
referred to as records
Many times, the data within these tables have relationships with one another, or dependencies.
A non relational database is document-oriented, meaning, all information gets stored in more
of a laundry list order.
SQL categorized as
• Alter is used to alter the table definition [ex: add or remove columns]
DQL consists of
DML consists of
Format
> select <column_Names> from <Table_Name> [Filters] ;
<column_Names> ==> you can give one or more columns with coulmns separated by comma
-- Column name are not case sensitive [columns can give in uppercase,Lower case or sentence case]
-- To retrive data from all columns ,You can use * instead of column names
-- * mean all
Comments:
SELECT:
-- To select the data from only required columns Ex: EMPNO,ENAME and Job from EMP table
-- For example if you want to calculate the yearly salary for an employee
--If you are using arthemetic operations you should not use asteric (*) in select statement
1.DISTINCT:
CustId CustName
100 Ram
101 Nithin
101 Sam
103 Vinay
103 Vinay
104 kiran
Output:
100
101
103
104
OutPut:
100 Ram
101 Nithin
101 Sam
103 Vinay
104 kiran
2.Where:
Ex: You have EMP and you want to retieve the employeess from only from DEPTNO 10
IN SQL if you are string you need enclose within single quotes.
3.AND Operator:
AND Operator deplays a record in all the conditions TRUE which are used in AND
4. OR Operator:
5.NOT Operator:
Metadata:
Fro example if you see in a table the table names and column names are metadata
because these gives the information about the table and data in the columns
Data:
so while given the data for string it is manadatory to enclose in the single quotes and give the string with
exact case.
Ex:
6. IN Operator:
Ex:
LIKE Operator:
Like operator is used in where clause to search for a specific pattern in a column.
WHERE CustomerName LIKE 'a%' Finds any values that start with "a"
WHERE CustomerName LIKE '%a' Finds any values that end with "a"
WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any position
WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the second position
WHERE CustomerName LIKE 'a_%' Finds any values that start with "a" and are at least 2 characters
in length
WHERE CustomerName LIKE 'a__%' Finds any values that start with "a" and are at least 3 characters
in length
WHERE ContactName LIKE 'a%o' Finds any values that start with "a" and ends with "o"
commit;
Order by
Ex:
select column1,column2,column3 from emp where condition order by <column1>
,<column2>,<column3> ASC| DESC;
-- select the data from EMP table and sort the data in asscending order on EMPNo;
-- -- select the data from EMP table and sort the data in descending order on EMPNO;
-- -- select the data from EMP table and sort the data in asscending order on EMPNo and ENAME and
JOb;