DATA QUERY LANGUAGE - SELECT STATEMENT

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.

 Logical Operators are
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';
 


  
 


SHARE

Milan Tomic

Hi. I’m Designer of Blog Magic. I’m CEO/Founder of ThemeXpose. I’m Creative Art Director, Web Designer, UI/UX Designer, Interaction Designer, Industrial Designer, Web Developer, Business Enthusiast, StartUp Enthusiast, Speaker, Writer and Photographer. Inspired to make things looks better.

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment

Important of Database privilages

Database privileges Privileges are the right or permission to execute particular SQL statements.                           System Se...