DBMS Exp5
DBMS Exp5
Experiment No-5
The most commonly used SQL command is SELECT statement. SQL SELECT statement is
used to query or retrieve data from a table in the database. A query may retrieve information
from specified columns or from all of the columns in the table. To create a simple SQL
SELECT Statement, you must specify the column(s) name and the table name. The whole
query is called SQL SELECT Statement.
Syntax-
SELECT is the SQL keyword that lets the database know that you want to retrieve
data.
[DISTINCT | ALL] are optional keywords that can be used to fine tune the results
returned from the SQL SELECT statement. If nothing is specified then ALL is
assumed as the default.
{*| [fieldExpression [AS newName]} at least one part must be specified, "*" selected
all the fields from the specified table name, fieldExpression performs some
computations on the specified fields such as adding numbers or putting together two
string fields into one.
FROM tableName is mandatory and must contain at least one table, multiple tables
must be separated using commas or joined using the JOIN keyword.
WHERE condition is optional, it can be used to specify criteria in the result set
returned from the query.
GROUP BY is used to put together records that have the same field values.
HAVING condition is used to specify criteria when working using the GROUP BY
keyword.
ORDER BY is used to specify the sort order of the result set.
Queries:
CURDATE(),CURRENT_TIME(),CURRENT_TIMESTAMP(),DATE(),DATEDIFF(),DAY
(),DAYNAME(),EXTRACT(),MINUTE(),MONTH(),WEEK(),NOW(),YEAR()
4) Retrieving
Staff_name
from staff table
whose salary is
greater
than 30000
mysql> select
staff_name
-> from staff
-> where salary
> 30000;
5) Retrieving staff_no and staff_name from staff and college table whose
salary is > 30000 and college_name is = college_name
6) Retrieving
all the salary from
the staff table
mysql> select
staff_name
-> from staff
-> where staff_name like'%s%';
mysql> select *
-> from staff
-> order by staff_no asc;
12) Retrieve max salary offered to the staff
Conclusion: Select queries with various clauses like group by, order by and
aggregate functions is implemented in mysql.