Select statement

SELECT statement has five major sections

1. SELECT key word 

2. column specification 

3. from key word

4. table or list of tables

5. where clause

Section 1, 2,3 and 4 are mandatory. 5 is optional. 

Explanation with examples  

Consider the table EMP with below structure

Empno Name DOB Salary
10 Mark 12/31/1970 4000
20 Adam 11/20/1980 4500
30 Gary 02/03/1995 3500
40 Lisa 06/14/1960 6000

1) All records

Suppose user needs to see all records from EMP table. Below statement will pull all records from the table. 

select from EMP;

Note :- 1) In SQL `*` means all columns. Here table has four columns.

2) `;` is the terminator for the SQL statement.

3) SQL is not case sensitive.

2) Selected columns

select empno,salary from EMP;

The above statement fetches all empno and salary columns from EMP table

3)  All records with where condition

select empno,salary from EMP where empno = 10;

 The above statement will fetch a record with empno as value 10

4)  All records using where condition and order by

select empno,salary from EMP where empno > 10 order by salary asc;

 The above statement will fetch all record with empno as value > 10 in a ascending order of salary

Select SQL statement has lot of features, some of them are pretty straight forward and some of them are really complex. Normally SQL cannot be learnt by just reading. You just need to practice SQLs with real examples. For that we need a database installed in an operating system.

Each database will have a client utility to manage SQLs. In Oracle Database supplied with  rwo SQL client utilities, SQL Plus and Oracle SQL DeveloperSQL Plus is a command line utility and Oracle SQL Developer is a graphical user interface(GUI)

List of standalone tools available in the market.

1. TOAD – www.quest.com

2. Oracle SQL Developer – www.oracle.com

3. PL/SQL Developer – http://www.allroundautomations.com

4. Advanced Query Tool(AQT) – www.querytool.com

 

Advertisements

Author: sqlandplsql

To learn more about the Oracle, SQL, PL SQL, Performance Tuning, Database Modeling, Ubuntu, MySQL etc .Suggestions, comments, feedbacks and referrals are highly appreciated.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s