Skip to content

Commit 0b632c5

Browse files
committed
added new answers
1 parent 0e00bc1 commit 0b632c5

1 file changed

Lines changed: 135 additions & 0 deletions

File tree

README.md

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,3 +686,138 @@ In this case, the duplicate row with Column1 = B has been retained in the final
686686
<div align="right">
687687
<b><a href="#table-of-contents">↥ back to top</a></b>
688688
</div>
689+
690+
## Q. What is difference between Correlated subquery and nested subquery?
691+
692+
**1. Correlated subqueries:**
693+
694+
Correlated subqueries are used for row-by-row processing. Each subquery is executed once for every row of the outer query.
695+
696+
A correlated subquery is evaluated once for each row processed by the parent statement. The parent statement can be a SELECT, UPDATE, or DELETE statement.
697+
698+
**Example:**
699+
700+
```sql
701+
--- Correlated Subquery
702+
SELECT e.EmpFirstName, e.Salary, e.DeptId
703+
FROM Employee e
704+
WHERE e.Salary = (SELECT max(Salary) FROM Employee ee WHERE ee.DeptId = e.DeptId)
705+
```
706+
707+
**2. Nested subqueries:**
708+
709+
A subquery can be nested inside other subqueries. SQL has an ability to nest queries within one another. A subquery is a SELECT statement that is nested within another SELECT statement and which return intermediate results. SQL executes innermost subquery first, then next level.
710+
711+
**Example:**
712+
713+
```sql
714+
--- Nested Subquery
715+
SELECT EmpFirstName, Salary, DeptId
716+
FROM Employee
717+
WHERE (DeptId, Salary) IN (SELECT DeptId, max(Salary) FROM Employee group by DeptId)
718+
```
719+
720+
<div align="right">
721+
<b><a href="#table-of-contents">↥ back to top</a></b>
722+
</div>
723+
724+
## Q. Differentiate UNION, MINUS, UNION ALL and INTERSECT?
725+
726+
- INTERSECT - It will give all the distinct rows from both select queries.
727+
- MINUS - It will give distinct rows returned by the first query but not by the second query.
728+
- UNION - It will give all distinct rows selected by either first query or second query.
729+
- UNION ALL - It will give all rows returned by either query with all duplicate records.
730+
731+
<div align="right">
732+
<b><a href="#table-of-contents">↥ back to top</a></b>
733+
</div>
734+
735+
## Q. Explain SQL Operators?
736+
737+
|Sl.No|Query | Description |
738+
|-----|------------------------------------------------|---------------------------------------------------|
739+
| 01. |SELECT c1 FROM t1 UNION [ALL] SELECT c1 FROM t2 |Select column c1 from a table named t1 and column c1 from a table named t2 and combine the rows from these two queries |
740+
| 02. |SELECT c1 FROM t1 INTERSECT SELECT c1 FROM t2 |Select column c1 from a table named t1 and column c1 from a table named t2 and return the intersection of two queries |
741+
| 03. |SELECT c1 FROM t1 MINUS SELECT c1 FROM t2 |Select column c1 from a table named t1 and column c1 from a table named t2 and subtract the 2nd result set from the 1st|
742+
| 04. |SELECT c1 FROM t WHERE c1 [NOT] LIKE pattern |Select column c1 from a table named t and query the rows using pattern matching % |
743+
| 05. |SELECT c1 FROM t WHERE c1 [NOT] in test_list |Select column c1 from a table name t and return the rows that are (or are not) in test_list |
744+
| 06. |SELECT c1 FROM t WHERE c1 BETWEEN min AND max |Select column c1 from a table named t and return the rows where c1 is between min and max|
745+
| 07. |SELECT c1 FROM t WHERE c1 IS [NOT] NULL|Select column c1 from a table named t and check if the values are NULL or not |
746+
747+
<div align="right">
748+
<b><a href="#table-of-contents">↥ back to top</a></b>
749+
</div>
750+
751+
#### Q. Explain correlated query work?
752+
#### Q. What is the SQL CASE statement used for?
753+
754+
*ToDo*
755+
756+
## # 6. SQL Clause
757+
758+
<br/>
759+
760+
## Q. What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
761+
762+
*ToDo*
763+
764+
<div align="right">
765+
<b><a href="#table-of-contents">↥ back to top</a></b>
766+
</div>
767+
768+
## # 7. SQL Order By
769+
770+
<br/>
771+
772+
<div align="right">
773+
<b><a href="#table-of-contents">↥ back to top</a></b>
774+
</div>
775+
776+
## # 8. SQL Insert
777+
778+
<br/>
779+
780+
<div align="right">
781+
<b><a href="#table-of-contents">↥ back to top</a></b>
782+
</div>
783+
784+
## # 9. SQL Update
785+
786+
<br/>
787+
788+
## Q. What are COMMIT and ROLLBACK in SQL?
789+
790+
**COMMIT** statement is used to end the current transaction and once the COMMIT statement is exceucted the transaction will be permanent and undone.
791+
792+
**Example:**:
793+
794+
```sql
795+
BEGIN
796+
UPDATE EmpDetails SET EmpName = "Arpit" where Dept = "Developer"
797+
COMMIT;
798+
END;
799+
```
800+
801+
**ROLLBACK** statement is used to end the current transaction and undone the changes which was made by that transaction.
802+
803+
**Syntax:** ROLLBACK [TO] Savepoint_name;
804+
805+
**Example:**:
806+
807+
```sql
808+
BEGIN
809+
Statement1;
810+
SAVEPOINT mysavepoint;
811+
BEGIN
812+
Statement2;
813+
EXCEPTION
814+
WHEN OTHERS THEN
815+
ROLLBACK TO mysavepoint;
816+
Statement5;
817+
END;
818+
END;
819+
```
820+
821+
<div align="right">
822+
<b><a href="#table-of-contents">↥ back to top</a></b>
823+
</div>

0 commit comments

Comments
 (0)