You are on page 1of 2

Assignment 2

The select statement is the basis for most SQL queries. If you want to get some data out

of the database to display it or use it for some other purpose, you're probably going to use a

select statement. The insert statement is used to add data to a table. Another statement is “update

statement” which is used to change the values of existing rows in a table. Addition to that this

week we will learn “delete statement” which is used to remove rows from the table.

For the SELECT statement/commend we need to use “SELECT” keyword. The syntax

should be like the following:

SELECT column_name, column_name2

FROM table_name;

If you need to select all, you need to use * sign. So syntax should be: SELECT * FROM

table_name; The asterisk means that all of the columns will be returned in this query. Some

database systems require a semicolon at the end of each SQL statement. Semicolon is the

standard way to separate each SQL statement in database systems that allow more than one SQL

statement to be executed in the same call to the server.

The ORDER BY keyword sorts the records in ascending order by default. To sort the

records in a descending order, you can use the DESC keyword. The syntax should be like the

following:

SELECT column_name, column_name

FROM table_name

ORDER BY column_name;

1
SQL Count Function returns the number of rows that matches specified criteria. Syntax
should be :

SELECT COUNT(column_name) FROM table_name;

Selecting rows from the table by using WHERE clause is :

SELECT column_name, column_name


FROM table_name
WHERE column_name = ‘ operator value’;

Selecting columns from the table by using the following syntax:

SELECT column_name AS title, column_name AS title (use AS for how you would like to
name the column)

FROM table_name

ORDER BY column_name

LIMIT number;

For inserting data , we use “INSERT INTO” statement which is used to insert new
records in a table. Syntax:

INSERT INTO table_name (column1,column2,column3,...)


VALUES (value1,value2,value3,...);

For updating data, we use “UPDATE” statement which is used to update existing records
in a table.
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;

For deleting data, we use “DELETE” statement which is used to delete rows in a table.

DELETE FROM table_name


WHERE some_column=some_value;

You might also like