SQL Statements

Home/SQL/SQL Statements

SQL use the term query as the name for its commands. Basically, all SQL code is written in the form of a query statement and then executed against a database.

PREMIUM TEMPLATES LIMITED TIME OFFER

ON SALE80% OFF

50+ Project Management Templates Pack
Excel PowerPoint Word

Advanced Project Plan & Portfolio Template
Excel Template

Business Presentations Templates Pack
PowerPoint Slides

20+ Excel Project Management Pack
Excel Templates

20+ PowerPoint Project Management Pack
PowerPoint Templates

10+ MS Word Project Management Pack
Word Templates


All SQL queries perform some type of data operation such as selecting data, inserting/updating data, or creating data objects such as SQL databases and SQL tables.
Each query statement begins with a clause such as SELECT,UPDATE, CREATE or DELETE and ends with semicolon(;)

Important point to be noted is that SQL is not case sensitive language which means SELECT and select have same meaning in SQL statements but MySQL make difference in table names. So if you are working with MySQL then you need to give table names as they exist in the database.

SQL Statements

We can classify the SQL statements as follows:

Data retrieval SELECT
Data manipulation language (DML) INSERT
UPDATE
DELETE
Data definition language (DDL) CREATE
ALTER
DROP
RENAME
TRUNCATE
Transaction control COMMIT
ROLLBACK
SAVEPOINT
Data control language (DCL) GRANT
REVOKE

Example table to explain these commands:

We will use the following table to explain the next few chapters, assume this table name as ‘Employee‘.

EID Department Name Salary

1

Research Ravi

22000

2

HR Mike

33000

3

Admin Neel

25000

4

Sales Anna

30000

5

HR Jo

20000

6

Admin Sunil

25000

7

Sales Mark

28000

8

Research Bill

35000

9

HR Tim

40000

10

Research Sharan

32000

Select Statement:

SELECT QUERY allows you to retrieve records from one or more tables from database.

Syntax:

[code language=”sql”] SELECT columns FROM tables WHERE <condition>

We often us WHERE Clause with SELECT Statement:

[code language=”sql”] Where {expression | column} “operator” {expression | column}[and|or] {expression | column} “operator” {expression | column}

Examples on SELECT:


Example 1: Retrieving entire data from Employee table:

[code language=”sql”] SELECT * FROM Employee

Here * indicates all the columns of the table.

Output:

EID Department Name Salary

1

Research Ravi

22000

2

HR Mike

33000

3

Admin Neel

25000

4

Sales Anna

30000

5

HR Jo

20000

6

Admin Sunil

25000

7

Sales Mark

28000

8

Research Bill

35000

9

HR Tim

40000

10

Research Sharan

32000


Example 2: Retrieving the data from Employee table where the department is Research:

[code language=”sql”] SELECT * FROM Employee WHERE Department="Research"

Here * indicates all the columns of the table.

Output:

EID Department Name Salary

1

Research Ravi

22000

8

Research Bill

35000

10

Research Sharan

32000


Example 1: Retrieving EID and Name from Employee table where salary is grater than 22000:

[code language=”sql”] SELECT EID, Name FROM Employee WHERE Salary>22000

Here * indicates all the columns of the table.

Output:

EID Name

2

Mike

3

Neel

4

Anna

6

Sunil

7

Mark

8

Bill

9

Tim

10

Sharan


We will see more examples on SELECT statement later with more examples.

LIMITED TIME OFFER
By |December 25th, 2012|SQL|1 Comment

About the Author:

PNRao is a passionate business analyst and having close to 10 years of experience in Data Mining, Data Analysis and Application Development. This blog is his passion to learn new skills and share his knowledge to make you expertise in Data Analysis (Excel, VBA, SQL, SAS, Statistical Methods, Market Research Methodologies and Data Analysis Techniques).

One Comment

  1. mano January 8, 2016 at 3:24 PM - Reply

    how to make not equal to statement in EXCEL ADO, give example

Leave A Comment


Related pages


conditional statement in vbexcel check boxexcel vba set cell colorexcel formula list 2007syntax in excel definitionvbs output to fileconvert macro to vbavba cuthow to convert xls file to xmlebook vba exceliserror with vlookupvba create filehow to break password in excel sheetmacro to combine multiple workbooks into oneexcel and macrosenable developer in excelexcel vba adodb connection string sql serverconvert from excel to csvrange vba variablemacro excel open filerange command vbaquality checklist template excelexcel collection vbamerge excel cellshow to merge cells in excellcheck box on excelexcel logical and operatorvba programsvba access create tableadodb connection vbadata modeling interview questions and answers pdffind duplicates excelautorun codeexcel multiple conditionsrecording macros in excelhide sheets in excelhow to find and delete duplicates in excelhow to use concatenate in excel 2007adodb providerexcel logical formulasadvanced filtering excel 2010transpose vbafso vbaapplication.worksheetfunctionexample of vlookup in excelexcel formula cell colourcool excel macro tricksline spacing in excelexcel vba for loopsmacro to save excel filecell coloring worksheetvba access export to excelhow to merge in excelexcel worksheet mergehow to build dashboards in excelsimple vba codeexcel bubble charthow to create bar chart in excel 2007excel logical and operatorhow to add command button in excelhlookup in excel 2010 with examplehow to check for duplicates excelvba userform examplehighlight column excelvba environmenthow to insert multiple rows in excel 2007insert worksheet excelexcel vba cellsvisual basic excel 2007 tutorial pdfvba oledb connection stringcreate userform in excel 2007excel range interior colorvba delete recordhow to use count function in excel 2007microsoft excel advanced filterexcel merge sheets into oneuse of hlookup in excelwhat is vlookup in ms excelcreating if statements in excelpowerpoint pyramid templatesumif excel vba