0% found this document useful (0 votes)
7 views4 pages

Exp 4

Hello his name is a new one day pickup line is the best way I can

Uploaded by

snapsites.in
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Exp 4

Hello his name is a new one day pickup line is the best way I can

Uploaded by

snapsites.in
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

**ANY Operator**

The `ANY` operator compares a value to any value returned by a subquery.

SELECT name, salary

FROM employees

WHERE salary > ANY (SELECT salary FROM employees WHERE department = 'HR');

This query returns employees whose salary is greater than any salary in the HR department.

2. **ALL Operator**

The `ALL` operator compares a value to all values in a subquery.

SELECT name, salary

FROM employees

WHERE salary > ALL (SELECT salary FROM employees WHERE department = 'HR');

```

This query returns employees whose salary is higher than every salary in the HR department.

3. **IN Operator**

The `IN` operator checks if a value is present in a list of values or a subquery result.

SELECT name, department

FROM employees

WHERE department IN ('HR', 'Sales', 'Marketing');

This query fetches employees who work in either HR, Sales, or Marketing departments.

4. **EXISTS Operator**

The `EXISTS` operator checks for the existence of rows returned by a subquery.
SELECT name

FROM employees e

WHERE EXISTS (SELECT * FROM departments d WHERE d.manager_id = e.employee_id);

This query lists employees who are managers (based on whether their `employee_id` appears as
`manager_id` in the `departments` table).

5. **NOT EXISTS Operator**

The `NOT EXISTS` operator checks if a subquery returns no rows.

SELECT name

FROM employees e

WHERE NOT EXISTS (SELECT * FROM projects p WHERE p.manager_id = e.employee_id);

This query returns employees who are not managing any projects.

6. **UNION Operator**

The `UNION` operator combines the result sets of two or more `SELECT` queries. Duplicate values are
removed.

SELECT name FROM employees

WHERE department = 'HR'

UNION

SELECT name FROM employees

WHERE department = 'Finance';

This query lists employees from either the HR or Finance departments without duplicates.

7. **INTERSECT Operator**

The `INTERSECT` operator returns rows that are common to both result sets.
SELECT name FROM employees

WHERE department = 'HR'

INTERSECT

SELECT name FROM employees

WHERE salary > 50000;

This query returns employees from HR whose salary is greater than 50,000.

8. **CONSTRAINTS**

Constraints are rules enforced on data columns, such as `PRIMARY KEY`, `FOREIGN KEY`, `UNIQUE`,
`CHECK`, and `NOT NULL`.

- **Adding a `PRIMARY KEY` constraint**:

CREATE TABLE departments (

department_id INT PRIMARY KEY,

department_name VARCHAR(50)

);

- **Adding a `FOREIGN KEY` constraint**:

CREATE TABLE employees (

employee_id INT PRIMARY KEY,

name VARCHAR(50),

department_id INT,

FOREIGN KEY (department_id) REFERENCES departments(department_id)

);

- **Adding a `CHECK` constraint**:


ALTER TABLE employees

ADD CONSTRAINT chk_salary CHECK (salary > 30000);

This constraint ensures that salary must be greater than 30,000.

You might also like