Document
Document
I can provide you with the SQL queries in a document format. Since I can't directly create
and save a .doc file, I'll give you the content that you can easily copy and paste into a Word
document or any text editor and save it as needed.
**Tables:**
**Queries:**
```sql
INSERT INTO emp (EMPNO, ENAME, JOB, HIREDATE, SAL, MODE, DEPTNO) VALUES
```
```sql
```
```sql
```
4. **Insert records into stud\_detail table:**
```sql
```
```sql
```
6. **List all the employees who have salary between 1000 and 2000:**
```sql
```
SELECT ENAME, JOB FROM emp WHERE JOB = 'Clerk' AND DEPTNO = 20;
```
```sql
```
```sql
```
```sql
```
11. **Display Registration number and name of students whose department is “computer
engineering”:**
```sql
```
12. **Add a column “SPOUSE” to the emp table that will hold the name of an employee’s
spouse:**
```sql
ALTER TABLE emp ADD SPOUSE VARCHAR(255); -- Assuming a maximum length of 255
for the spouse's name
```
```sql
```
```sql
```
```
```sql
```
17. **Copy all the information of department 20 into the “ManagerHist” table:**
```sql
```
* **Join:** A JOIN clause is used to combine rows from two or more tables, based on a
related column between them.
* **Self Join:** A self join is a join operation where a table is joined with itself. It's useful
for querying hierarchical data or comparing rows within the same table.
19. **Retrieve employee number, employee name and their department name, in
department name order:**
```sql
SELECT e.EMPNO, e.ENAME, d.DNAME
FROM emp e
ORDER BY d.DNAME;
```
```sql
--This assumes there's a location for employees. If not, and you meant department
location:
```
21. **Display the name, salary and department number of employees whose salary is more
than 10000:**
```sql
SELECT ENAME, SAL, DEPTNO FROM emp WHERE SAL > 10000;
```
22. **List the employee name, job, salary and department name for everyone in the
company except clerks:**
```sql
SELECT e.ENAME, e.JOB, e.SAL, d.DNAME
FROM emp e
```
```sql
```
24. **List all employees by name and number along with their manager’s name and
number:**
```sql
--This requires that the emp table has a manager ID (e.g., MGR). Assuming it does:
FROM emp e
LEFT JOIN emp m ON e.MGR = m.EMPNO; -- Assuming MGR is the manager's employee
number
```
25. **Display all the employees who earn less than their managers:**
```sql
--Again, assuming an MGR column in the emp table:
SELECT e.ENAME
FROM emp e
```