What is basic SELECT statement?


SELECT Statement

A SELECT statement retrieves data from the database. With SELECT statement PROJECTION, SELECTION and JOIN can be performed on database tables.

As data in relational database is stored in TABLES. TABLE has ROW and COLUMN structure. With SELECT statement all rows and all columns can be retrieved, this is known as PROJECTION. But, if rows and columns are retrieved on the basis of some condition, it is known as SELECTION. And suppose if some information is needed and that is stored in two or more different tables but are related, use JOINS to retrieve it from two or more tables.

In SQL, basic SELECT statements are as follows:

SELECT *
FROM [table_name];

SELECT [column1][column2][column3], ..... 
FROM  [table_name];

SELECT and FROM are known as clauses. 

SELECT clause allows to specify columns to be selected from the database table. 

FROM clause allows to specify table name that has those column to be selected.

Semicolon at the end of SELECT statement specify the end of SQL statement. We can specify more than one SQL statement by using semicolon as separator.

If * is specified in SELECT clause, that means retrieve all columns of the TABLE.

Consider the following database table "EMP" from Oracle:



Select all columns and all rows from EMP:

SELECT 
FROM EMP;

Output:


Select specific columns (e.g. employee number and employee name) from EMP:

SELECT 
EMPNOENAME
FROM EMP;

Output:

WHERE clause is used to filter the rows retrieved from TABLE. A condition is used to restrict the row selection. Column names, expressions, constants and logical operators are used to build a filter condition. 

SELECT
 [column1][column2][column3], ..... 
FROM  [table_name]
WHERE [condition];

Select employee names working in department 10:

SELECT ENAME
FROM EMP
WHERE DEPTNO = 10 ; 

Output:

Query condition includes character sequence (String) in single quotes and is case sensitive. 

Select employee number, employee name and department number of an employee 'CLARK':

SELECT EMPNO, ENAME, DEPTNO
FROM EMP 
WHERE ENAME = 'CLARK' ;

Output:
                                               


Comparison conditions can be formed using logical operators like =, >, >=, <, <= and <> (Not equal to).

Select employee name and department number of all employee with salary less than 1000 Rs. :

SELECT 
ENAME, DEPTNO
FROM EMP 
WHERE SAL < 1000 ;

Output:

Comments

  1. Great Article. Thank you for sharing! Really an awesome post for every one.

    IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

    ReplyDelete
  2. you post good article. i like this article. please visit my website.Cooking Range Repair Dubai

    ReplyDelete

Post a Comment

Popular posts from this blog

With the help of block diagram explain the architecture of a DBMS.

What do you mean by data model? What are different types of data models?

What are the different types of database users?