Instruction
1
To retrieve database tables the stored information make a select query - SELECT. You have relationships between tables, data can be taken under the respective conditions of all columns of related tables. All the columns you want to list after the SELECT statement. Used in the query table, specify in the FROM clause. In its simplest form, a select query displays all rows from the specified columns of the specified table: SELECT col1, col2 FROM my_table.
2
If necessary, set the condition to fetch the rows. The condition is specified by a WHERE clause. Set the desired setting following the instructions. Here can also be used by the calculation function and comparison operations. So, the statement view WHERE col1 > 3 allows you to display table rows in which the value of col1 is greater than 3. To set the desired expressions use combinations of operators AND, OR, and conditional SQL statements.
How to write a SQL query
3
To insert new rows into a table write a query to INSERT. It can be used to insert new data of the same type that already exist in the table. The syntax of this operator is very simple: INSERT INTO my_table (col1, col2, col3) VALUES (‘new_data1’, ‘new_data2’, ‘new_data3’). Here the VALUES statement sets the values of the new row for each existing column of the table my_table.
4
Change the data in any row of the table is performed using UPDATE query. And you can put a condition of selection WHERE, which is to change the information in the database. Determine what data to modify and condition the fulfillment of your request. To do this, write a string like: UPDATE my_table SET col1 = ‘new_data1’, col3 = ‘new_data3’ WHERE col3 = 10. The query will perform the data change specified in the SET statement only if you satisfy the conditions in the WHERE clause.
5
The DELETE query is written to delete the whole row from the data table. And the row is deleted only when you specify a execution conditions of the WHERE clause. Write down the expression: DELETE FROM my_table WHERE col1 = ‘data1’. When you run this query deletes row in the table that contains the column col1, the value of data1.