Tuesday, May 29, 2007

SQL Statement Example for SELECT, UPDATE and DELETE

Below is Sql Statement with Example provided. It will help SQL beginner more understanding about the usage of SQL statement. For more information about SQL Syntax, click here.

Name

Income

Company

Position

Angle4500Ajax Tech LimitedManager
Helen6900Programmingschools LimitedCEO
Micheal4000SQLTutorial LimitedDBA
Nick5000Programmingschools LimitedProgrammer
Table Name : Testing

SQL STATEMENT - Example Result with SQL Statement
Select All data from a table (same as above table)-
SELECT * FROM TESTING


SELECT NAME,COMPANY FROM TESTING

namecompany
AngleAjax Tech Limited
HelenProgrammingschools Limited
MichealSQLTutorial Limited
NickProgrammingschools Limited

SELECT DISTINCT COMPANY FROM TESTING

company
Ajax Tech Limited
Programmingschools Limited
SQLTutorial Limited

SELECT COUNT(*) FROM TESTING

4

SELECT * FROM TESTING WHERE NAME='HELEN'

NameIncomeCompanyPosition
Helen6900Programmingschools LimitedCEO

SELECT * FROM TESTING WHERE NAME='HELEN' AND COMPANY='Programmingschools Limited'
NameIncomeCompanyPosition
Helen6900Programmingschools LimitedCEO

SELECT * FROM TESTING WHERE NAME='HELEN' OR COMPANY='Pragrammingschools Limited'

NameIncomeCompanyPosition
Helen6900Programmingschools LimitedCEO
Nick5000Programmingschools LimitedProgrammer

SELECT * FROM TESTING WHERE COMPANY IN ('Pragrammingschools Limited')

NameIncomeCompanyPosition
Helen6900Programmingschools LimitedCEO
Nick5000Programmingschools LimitedProgrammer

SELECT * FROM TESTING WHERE COMPANY LIKE '%PROGRAMMINGSCHOOLS%'

NameIncomeCompanyPosition
Helen6900Programmingschools LimitedCEO
Nick5000Programmingschools LimitedProgrammer

SELECT * FROM TESTING WHERE ORDER BY COMPANY
NameIncomeCompanyPosition
Angle4500Ajax Tech LimitedManager
Helen6900Programmingschools LimitedCEO
Nick5000Programmingschools LimitedProgrammer
Micheal4000SQLTutorial LimitedDBA

SELECT * FROM TESTING WHERE ORDER BY COMPANY DESC

NameIncomeCompanyPosition
Micheal4000SQLTutorial LimitedDBA
Helen6900Programmingschools LimitedCEO
Nick5000Programmingschools LimitedProgrammer
Angle4500Ajax Tech LimitedManager

SELECT SUM(INCOME),COMPANY FROM TESTING GROUP BY COMPANY

SUM(Income)Company
4500Ajax Tech Limited
11900Programmingschools Limited
4000SQLTutorial Limited

SELECT COUNT(*),COMPANY FROM TESTING GROUP BY COMPANY

COUNT(*)COMPANY
1Ajax Tech Limited
2Programmingschools Limited
1SQLTutorial Limited

SELECT SUM(INCOME),COMPANY FROM TESTING GROUP BY COMPANY HAVING (SUM(INCOME)>5000)

SUM(INCOME)COMPANY
11900Programmingschools Limited

For Sql Update and Sql Delete statement, click here

1 comment:

Leslie Lim said...

I have found your blogs to be friendly and welcoming. Thanks for making this one. I really enjoy reading and surfing it. Try to visit my site @ www.imarksweb.org

Zea