SQL Questions

Q:

What type of Joins have you used?

Answer

The knowledge of Joins is a MUST for every interviewee. Most SQL programmers have used inner join and  outer join[left/right]; but the catch point here is to also mention cross join and self-join.


 

Report Error

View answer Workspace Report Error Discuss

Subject: SQL

1 2496
Q:

How will you find the 3rd max salary in the employment table?

Answer

SELECT DISTINCT(salary) FROM emp as e1 


WHERE (3) = (SELECT COUNT(DISTINCT(salary)) FROM emp as e2  WHERE e1.salary <= e2.salary)

Report Error

View answer Workspace Report Error Discuss

Subject: SQL

1 2455
Q:

What is the difference between UNION and UNION ALL?

Answer

UNION selects only distinct values whereas UNION ALL selects all values and not just distinct ones

Report Error

View answer Workspace Report Error Discuss

Subject: SQL

0 2346
Q:

Difference between a query and a statement in SQL?

Answer

An SQL statement is a string of characters that conforms to the syntax and format specified in the international standard.


A query is a statement that returns a record-set.

Report Error

View answer Workspace Report Error Discuss

Subject: SQL

0 2343
Q:

The multi part identifier could not be bound is

Answer

One of the most common errors that you might face in join statements is 


 


Server: Msg 4104, Level 16, State 1, Line 1
The multi-part identifier could not be bound.


 


A multipart identifier is any description of a field or table that contains multiple parts - for instance MyTable.SomeRow - if it can't be bound that means there's something wrong with it - either you've got a simple typo, or a confusion between table and column. It can also be caused by using reserved words in your table or field names and not surrounding them with [].


 


The main reason for this error is that the source table cannot be found, for example if you have statement such as Table1.OrderDate, and then if you get error above, this means that Table1 cannot be found in the query. Sometimes you can see that source table exists in the query, but T-SQL cannot understand it, especially when you write join statements.

Report Error

View answer Workspace Report Error Discuss

0 2330
Q:

What are the difference between clustered and a non-clustered index?

Answer

- A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore table can have only one clustered index. The leaf nodes of a clustered index contain the data pages.


- A non clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a non clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows.

Report Error

View answer Workspace Report Error Discuss

Subject: SQL

0 2282
Q:

What is Aggregate Functions?

Answer

Aggregate functions perform a calculation on a set of values and return a single value. Aggregate functions ignore NULL values except COUNT function. HAVING clause is used, along with GROUP BY, for filtering query using aggregate values.


Following functions are aggregate functions. 


AVG, MIN CHECKSUM_AGG, SUM, COUNT, STDEV, COUNT_BIG, STDEVP, GROUPING, VAR, MAX. VARP

Report Error

View answer Workspace Report Error Discuss

Subject: SQL

0 2194
Q:

What are PL/SQL cursor exceptions?

Answer

Cursor_Already_Open,  Invalid_Cursor.

Report Error

View answer Workspace Report Error Discuss

Subject: SQL

0 2173