0% found this document useful (0 votes)
17 views2 pages

Answers For Page 1 Questions

The document provides answers to questions about SQL clauses and functions. It discusses the differences and uses of clauses like WHERE, HAVING, GROUP BY and JOIN. It also provides examples of aggregate functions and different types of JOINs. Sample SQL queries are given to demonstrate DELETE, ORDER BY LIMIT, and HAVING clauses.

Uploaded by

kartheekalla9999
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)
17 views2 pages

Answers For Page 1 Questions

The document provides answers to questions about SQL clauses and functions. It discusses the differences and uses of clauses like WHERE, HAVING, GROUP BY and JOIN. It also provides examples of aggregate functions and different types of JOINs. Sample SQL queries are given to demonstrate DELETE, ORDER BY LIMIT, and HAVING clauses.

Uploaded by

kartheekalla9999
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/ 2

Answers for page 1 questions

1. WHERE Clause is used to filter the records from the table


based on the specified condition. HAVING Clause is used to
filter record from the groups based on the specified condition.

2. SUM, COUNT, AVG, and MAX are commonly used aggregate


functions. So, understanding the syntax of SQL Server
aggregate functions is essential for anyone working with
databases and looking to analyze data efficiently.

3. The DELETE statement removes rows one at a time and


records an entry in the transaction log for each deleted row.
TRUNCATE TABLE removes the data by deallocating the data
pages used to store the table data and records only the page
deallocations in the transaction log. DELETE command is
slower than TRUNCATE command. And truncate works faster

4. . UNION and UNION ALL in SQL are used to retrieve data


from two or more tables. UNION returns distinct records from
both the table, while UNION ALL returns all the records from
both the tables.

5. A CTE can be used many times within a query, whereas a


subquery can only be used once. This can make the query
definition much shorter, but it won't necessarily result in
improved performance. Subqueries can be used in a WHERE
clause in conjunction with the keywords IN or EXISTS , but
you can't do this with CTEs.

6. Difference between row_number vs rank vs dense_rankThe


row_number gives continuous numbers, while rank and
dense_rank give the same rank for duplicates, but the next
number in rank is as per continuous order so you will see a
jump but in dense_rank doesn't have any gap in rankings.

For example google it


There are four main types of JOINs in SQL: INNER JOIN, OUTER
7.
JOIN, CROSS JOIN, and SELF JOIN. However, remember that
OUTER JOINS have two subtypes: LEFT OUTER JOIN and RIGHT
OUTER JOIN. ( please see examples in google)
8

 GROUP BY clause is used with the SELECT statement.


 In the query, the GROUP BY clause is placed after the WHERE clause.
 In the query, the GROUP BY clause is placed before the ORDER BY clause if
used.
 In the query, the Group BY clause is placed before the Having clause.
 Place condition in the having clause.

Answers for page 2 SQL Queries

1.DELETE FROM [SampleDB].[dbo].[Employee]


WHERE ID NOT IN
(
SELECT MAX(ID) AS MaxRecordID
FROM [SampleDB].[dbo].[Employee]
GROUP BY [FirstName],
[LastName],
[Country]
);

2.SELECT * FROM `employee_table` ORDER BY `sal` DESC


LIMIT 1 OFFSET 2;

3. SELECT OrderID, COUNT(OrderID)


FROM Orders
GROUP BY OrderID
HAVING COUNT(OrderID) > 1

You might also like