Topics: SQL, Articles with example SQL code, PostgreSQL Pages: 2 (414 words) Published: August 25, 2013
SQL Syntax
Select Statement
The SQL SELECT statement is used to select data from a SQL database table. This is usually the very first SQL command every SQL newbie learns and this is because the SELECT SQL statement is one of the most used SQL commands. SELECT "column_name" FROM "table_name"

The SQL DISTINCT clause is used together with the SQL SELECT keyword, to return a dataset with unique entries for certain database table column. SELECT DISTINCT "column_name"
FROM "table_name"
The SQL WHERE clause is used to select data conditionally, by adding it to already existing SQL SELECT query. We are going to use the Customers table from the previous chapter, to illustrate the use of the SQL WHERE command. SELECT "column_name"

FROM "table_name"
WHERE "condition"
The SQL AND clause is used when you want to specify more than one condition in your SQL WHERE clause, and at the same time you want all conditions to be true. The SQL OR statement is used in similar fashion and the major difference compared to the SQL AND is that OR clause will return all rows satisfying any of the conditions listed in the WHERE clause. SELECT "column_name"

FROM "table_name"
WHERE "simple condition"
{[AND|OR] "simple condition"}+
Order By
The SQL ORDER BY clause comes in handy when you want to sort your SQL result sets by some column(s). For example if you want to select all the persons from the already familiar Customers table and order the result by date of birth, you will use the following statement: SELECT "column_name"

FROM "table_name"
[WHERE "condition"]
ORDER BY "column_name" [ASC, DESC]

Insert Into Statement
The SQL INSERT INTO syntax has 2 main forms and the result of either of them is adding a new row into the database table. The first syntax form of the INSERT INTO SQL clause doesn't specify the column names where the data will be inserted, but just their values:

INSERT INTO "table_name" ("column1", "column2", ...)
VALUES ("value1",...
Continue Reading

Please join StudyMode to read the full document

Become a StudyMode Member

Sign Up - It's Free