Standart Query Language (SQL) is the standart language for relational database management systems. SQL allows you to create, update or retrieve data from a database. There are plenty of relational database management systems such as Oracle, Microsoft SQL Server, Access, Sybase etc. Even though these systems are using SQL to communicate, they have their own functions and extensions. However, there are standart SQL commands that are same in all relational database management systems.
Some of the common commands are “SELECT”, “INSERT”, “UPDATE”, “SET”, “CREATE” and “DROP”
TablesThe date for databases are stored on tables including columns and rows. Columns have name, data type and other attributes such as length of characters. Rows include the data related to the columns. Here is an example of a table named “Highest Towns”.
Rank, Country, City, Height are the colums. Here are rows contain data for the table:
Highest Towns |
---|
Rank |
Country |
City |
Height (m) |
Height (ft) |
---|
1 |
Peru |
La Rinconada |
5,100 |
16,728 |
2 |
China |
Wenquan |
5,019 |
16,467 |
3 |
Argentina |
El Aguilar |
4,895 |
16,062 |
4 |
India |
Hikkim |
4,572 |
15,000 |
QueriesIn order to select data, create or alter the tables, you will need to run some queries.
Select StatementSelect statement allows you to retrieve the data which is based on the criteria you defined. Here is general format for select statement:
SELECT "Column1", "Column2"
FROM "Table1"
WHERE "Condition1"
For the column name you can pick any columns you like. If you would like to have all the columns you can use “*” to select all columns in a given table.
FROM is used to specify the table name which its column names are selected in the beginning of the statement.
WHERE is the optional statement to define criterias for the selection of the data.
WHERE ClauseFollowing conditional operators can be used for WHERE clause:
= |
Equal |
> |
Greater than |
< |
Less than |
>= |
Greater than or equal |
<= |
Less than or equal |
<> |
Not equal to |
LIKE |
Specify wild cards |
LIKE in WHERE clauseHere are some examples of like used in where statement:
SELECT * FROM EmployeeInfo
WHERE FirstName LIKE 'John'
This statement searches for rows where the first name column is exaclty “John”
SELECT * FROM EmployeeInfo
WHERE LastName LIKE '%Ree%'
This statement searches for rows where the last name column includes “Ree” phrase any where in between.
Author
İsmail Erdem Sırma
Senior Software Engineer