DBMS Select command usage
DBMS Select command usage
SELECT Command:
Examples on retrieving data from a single table using
i) SELECT statement
ii) SELECT statement with where clause (Comparison Operators, AND, OR,
NOT, IN, BETWEEN, LIKE)
iii) ORDER BY clause (sort by column name)
iv) LIMIT clause
Case 1:
i. SELECT:
The SELECT statement in MySQL is used to retrieve data from one or more
tables in a database. The basic syntax of a SELECT statement is as follows:
Syntax:
SELECT column1, column2, ...FROM table_name;
Case 2:
i. SELECT statement with where clause
SELECT statement with where clause syntax
SELECT column1, column2, ...FROM table_name WHERE condition;
=: Equal to
!= or <>: Not equal to
<: Less than
<=: Less than or equal to
>: Greater than
>=: Greater than or equal to
Equal to (=):
Used to check if two expressions are equal.
SELECT * FROM table_name WHERE column_name = value;
Not equal to (!= or <>):
Used to check if two expressions are not equal.
SELECT * FROM table_name WHERE column_name != value;
or
SELECT * FROM table_name WHERE column_name <> value;
Greater than (>):
Used to check if one expression is greater than another.
SELECT * FROM table_name WHERE column_name > value;
Less than (<):
Used to check if one expression is less than another.
SELECT * FROM table_name WHERE column_name < value;
Greater than or equal to (>=):
Used to check if one expression is greater than or equal to another.
SELECT * FROM table_name WHERE column_name >= value;
Less than or equal to (<=):
Used to check if one expression is less than or equal to another.
SELECT * FROM table_name WHERE column_name <= value;
IS NULL:
Used to check if a column contains a NULL value.
SELECT * FROM table_name WHERE column_name IS NULL;
IS NOT NULL:
Used to check if a column does not contain a NULL value.
SELECT * FROM table_name WHERE column_name IS NOT NULL;
FROM table-name
FROM table_name
FROM table_name
Example:
FROM employees
FROM table_name
Example:
FROM products
FROM table_name
Example:
FROM products
Case 3:
ORDER BY clause
The ORDER BY clause in a SELECT statement is used to sort the result set
based on one or more columns. Here's the basic syntax:
FROM table_name
Example:
FROM employees
Case 4:
FROM table_name
LIMIT number_of_rows;
Example:
FROM employees
LIMIT 5;
Viva Questions: