Sql extra
Sql extra
Sql extra
Remove an attribute
ALTER TABLE table_name DROP attribute;
Remove primary key from the table
ALTER TABLE table_name DROP PRIMARY KEY;
Renaming of columns
ALTER TABLE table_name
RENAME COLUMN old_column_name TO new_column_name;
WHERE Clause
The WHERE clause filters rows based on specified conditions within a
SQL query.
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Ex:
SELECT *
FROM employees
WHERE salary > 50000;
ORDER BY Clause
The ORDER BY clause is used to sort the result set of a query either
in ascending (default) or descending order based on one or more
columns.
SELECT column1, column2, ...
FROM table_name
ORDER BY column1 [ASC|DESC], column2 [ASC|DESC], ...;
Ex: SELECT emp_name, salary
FROM employees
ORDER BY salary DESC;
SELECT emp_name
FROM employees
WHERE emp_name LIKE 'J%';
2. SUBSTRING() Function:
The SUBSTRING() function extracts a substring from a string.
Example:
If you want to extract a part of a string from the description column
starting at position 3 and including the next 5 characters:
SELECT emp_name
FROM employees
WHERE department = 'Sales'
UNION
SELECT emp_name
FROM employees
WHERE department = 'Marketing';
4. Intersection
The INTERSECT operator returns the common rows between the result sets of two or more SELECT
statements.
Example:
Retrieve the employees who are in both 'Sales' and 'Marketing' departments:
SELECT emp_name
FROM employees
WHERE department = 'Sales'
INTERSECT
SELECT emp_name
FROM employees
WHERE department = 'Marketing';
5. Difference
The EXCEPT or MINUS operator returns rows from the first query that
are not present in the result set of the second query.
Example:
Retrieve employees who are in 'Sales' but not in 'Marketing':
SELECT emp_name
FROM employees
WHERE department = 'Sales'
EXCEPT
SELECT emp_name
FROM employees
WHERE department = 'Marketing';
6. Join
Joins combine rows from two or more tables based on a related column
between them.
Example:
Retrieve information from two tables (employees and departments)
based on a common column (department_id):
SELECT e.emp_name, d.department_name
FROM employees e
INNER JOIN departments d ON e.department_id = d.department_id;
Write all the single row, multiple row ,
aggregate functions ,description and their
examples with output from page no
158,161,162,164,166.