Structured Query Language (SQL) Syntax

May 1, 2011 | Posted by: admin | Database | 1 Comment

Gopiplus.com DatabaseThis article is about the database language Structured Query Language (SQL). It is a database computer language designed for managing data in relational database management systems (RDBMS). In this page, i have listed the SQL syntax for each of the SQL commands. this is an easy reference for someone to learn Structured Query Language (SQL).

Select Statement
SELECT “column_name” FROM “table_name”

Drop Table Statement
DROP TABLE “table_name”

Truncate Table Statement
TRUNCATE TABLE “table_name”

Distinct
SELECT DISTINCT “column_name”
FROM “table_name”

Group By
SELECT “column_name1″, SUM(“column_name2″)
FROM “table_name”
GROUP BY “column_name1″

The GROUP BY clause is used to project rows having common values into a smaller set of rows.

Delete From Statement
DELETE FROM “table_name”
WHERE {condition}

The FROM clause which indicates the table(s) from which data is to be retrieved.

Where
SELECT “column_name”
FROM “table_name”
WHERE “condition”

The WHERE clause includes a comparison predicate, which restricts the rows returned by the query

And/Or
SELECT “column_name”
FROM “table_name”
WHERE “simple condition”
{[AND|OR] “simple condition”}+

In
SELECT “column_name”
FROM “table_name”
WHERE “column_name” IN (‘value1′, ‘value2′, …)

Between
SELECT “column_name”
FROM “table_name”
WHERE “column_name” BETWEEN ‘value1′ AND ‘value2′

Like
SELECT “column_name”
FROM “table_name”
WHERE “column_name” LIKE {PATTERN}

Order By
SELECT “column_name”
FROM “table_name”
[WHERE "condition"]
ORDER BY “column_name” [ASC, DESC]

The ORDER BY clause identifies which columns are used to sort the resulting data.

Count
SELECT COUNT(“column_name”)
FROM “table_name”

Having
SELECT “column_name1″, SUM(“column_name2″)
FROM “table_name”
GROUP BY “column_name1″
HAVING (arithematic function condition)

The HAVING clause includes a predicate used to filter rows resulting from the GROUP BY clause.

Create Table Statement
CREATE TABLE “table_name”
(“column 1″ “data_type_for_column_1″,
“column 2″ “data_type_for_column_2″,… )

Insert Into Statement
INSERT INTO “table_name” (“column1″, “column2″, …)
VALUES (“value1″, “value2″, …)

Update Statement
UPDATE “table_name”
SET “column_1″ = [new value]
WHERE {condition}

Comments (1)

 

  1. James Carter says:

    In this article the description is very clear and helpful. It describes everything clearly. I enjoyed the article very much. I also have read a article about this topic here “http://www.techyv.com/article/best-practices-using-structured-query-language-sql”which is very helpful also.

Leave a Reply