DQL -DATA QUERY LANGUAGE
i) SQL data query language (DQL) is one of the most commonly used to query one or more table to get the information they want.
ii) SELECT is DATA QUERY LANGUAGE.
iii)SELECT statement is used for retrieval of data from the tables and produce reports.
iv) SQL allows a tables (relation) to have two or more rows(tuples) that are identical in all their attribute(column) values.
A typical SQL statement of SELECT operation can be made up of two or more of the clause.
Fig: Basic SQL Statement |
Syntax:
SELECT [ALL/DISTINCT] col_name
FROM table(s)_name
WHERE condition
GROUP BY clause col(s)_name
HAVING condition
ORDER_BY column(s)_name;
In this SELECT and FROM clause is Mandatory reaming clause are Optional.
These clause included in the SELECT statement only when functions provided by them are required in the query.
Example:
Q1. SELECT * FROM EMP;
(*) indicate all columns
This query display all data from EMP relation listed in the FROM clause.
2) SELECT ENAME, SAL FROM EMP;
This query involves only the ENAME, SAL columns from EMP relation.
WHERE CLAUSE
3) SELECT * FROM EMP where deptno=10;
Query display data of EMP relation those dept no is 10
3) SELECT ENAME, SAL FROM EMP where JDATE='02-MAY-1982';
Query display data of EMP relation those JDATE IS 02 may 1982
Note := Character and date values must be enclosed in ' ' in where clause
because character is case sensitive and date is format sensitive.
By default date format generally used in ORACLE 'dd-mon-yy'
We can also use logical operators in WHERE CLAUSE.
A logical conditions combines the result of two component conditions to produce a single result base on them.
1) AND
2)OR
3) NOT
Examples:
AND OPERATOR
Write a query to display all data of employees those who are working in computer dept and salary more than 50000
SELECT * FROM EMP
WHERE DNAME= 'Computer' AND SALARY>50000;
OR OPERATOR
Write a query to display all data of employees those who are working in computer dept OR those whose salary more than 50000
SELECT * FROM EMP
WHERE DNAME= 'Computer' OR SALARY>50000;
NOT OPERATOR
Write a query to display name of all employees except department PRODUCTION.
SELECT ENAME FROM EMP
WHERE DNAME<>'Production';
0 comments:
Post a Comment