I know you are looking for such an important question to crack upcoming interview. So, without wasting time. We move towards SQL interview questions and answers.
What is the difference between ‘HAVING’ CLAUSE and a ‘WHERE’ CLAUSE?
HAVING clause use only with SELECT statement. It is usually used in a GROUP BY clause and whenever GROUP BY is not used, HAVING behaves like a WHERE clause. Having clause is use with the GROUP BY function. But, Where as clause applies to each row before they are a part of GROUP BY function.
What are the various levels of constraints?
Constraints are the physical and logical address of a column. It entitles data uniqueness. There are two levels of a constraint:
- Column level constraint
- Table level constraint
What are aggregate and scalar functions?
Aggregate functions use to check mathematical calculation and returns a single value. These calculations come from the columns in a table. For example- max(),count() calculate on numeric values in column.
Let’s move to the next question in this SQL Interview Questions and answers.
Name the operator which is used in the query for pattern matching?
LIKE operator uses for pattern matching, and it uses as : % – It matches zero or more characters.
For example- select * from students where studentname like ‘a%’
_ (Underscore) – it matches exactly one character.
For example- select * from student where studentname like ‘abc_’
Can you please tell about character-manipulation functions and its types?
The functions which help to manipulate, extract, trim and edit the string. These strings can manipulate by character manipulation functions.
The character manipulation functions in SQL are as follows:
A) CONCAT (joining two or more values): This function uses to join two or more values together. The second string is always appended to the end of the first string.
B) SUBSTR: This function returns a segment of a string from a given start point to a given endpoint.
C) LENGTH : This function returns the length of the string in numerical form plus blank spaces.
D) INSTR: This function calculates the precise numeric location of a character or word in a string.
E) LPAD : It returns the padding of the left-side character value.
F) RPAD: For a left-justified value, it returns the padding of the right-side character value.
G) TRIM: This function removes all defined characters from the beginning, end, or both ends of a string. It also reduced the amount of wasted space.
H) REPLACE : It helps to replace string with a new string.
What is the difference between the RANK() and DENSE_RANK() functions?
The RANK() function in the result set defines the rank of each row within your ordered partition. If both rows have the same rank, the next number in the ranking will be the previous rank plus a number of duplicates. If we have three records at rank 4, for example, the next level indicated is 7.
The DENSE_RANK() function assigns a distinct rank to each row within a partition based on the provided column value, with no gaps. It always indicates a ranking in order of precedence. This function will assign the same rank to the two rows if they have the same rank, with the next rank being the next consecutive number. If we have three records at rank 4, for example, the next level indicated is 5.
About SQL Interview Questions and Answers
These questions collected from different forums and educational websites. These questions helps you to learn some basic as well as some professional level questions.
We are updating this section periodically. You can add your questions in comments section to improve this page.
If you find any question helpful you can mention this question here. You can share your experience and learning process.
We are always open to listen from your side.