how to write sql queries

Last updated on October 30th, 2015 at 05:28 pm

Relational Database Management system(RDBMS) contains many tables . These tables are the basic storage in Database. Tables contains the information about something in the real world for example customers ,employees ,deptTables in the database contain zero to many rows.

SQL which stands for “Structured Query Language” which is pronounced as “SQL” or “sequel . SQL is a query language used for accessing and modifying information in one or more data tables and rows of a database.

Sql has  the following advantages
1) Efficient
2) Simple to write
3) Functionally complete as they can be used to completely retrieve  and manipulate  the data in the tables

Related: Oracle sql decode processing

It is an ANSI/ISO standard. It has become a Standard Universal Language used by most of the relational database management systems (RDBMS). Some of the RDBMS systems are: Oracle, Microsoft SQL server, Sybase etc.

Some of the sql basics which will help in writing sql queries

Select : It is used to retrieve data from the RDBMS
Insert: It is used to insert new rows in the RDBMS
Update: It is used to update the rows in the RDBMS

It can be said that , SQL is a non-procedural, English-like language that processes data in groups of records rather than one record at a time.

How to write sql queries
1) We must first understand the requirement
2) All RDBMS  have same Sql format but few things in syntax may differ.So we should refer the specfic database manual to learn about it
3) If we are just retrieving the data,then select is the first keyword to use
a) We must describe the table from where data has to retrive
b) We choose the column according to the requirement
c) If any filter condition is there, we should specify it
d)if  multiple tables are there,then join condition must be used

Related: Oracle sql tutorial: Basic Sql statement


select emp_id,sal from emp where sal > 10000;

Here emp_id,sal are the column choosen
emp is the table
where sal > 10000 is the filter condition

4) If we are manipulating data in the table,then update or insert need to be used


update emp set sal=120000 where emp_id=2;


emp is the table
update is the keyword for manipulation
set  is the keyword used in conjunction with update
sal=12000 is  the manipulation
where emp_id=2 is the filter condition

Leave a Comment

Your email address will not be published. Required fields are marked *