45 Essential SQL Interview Questions: Hire A Developer Apply As A Developer Log in
45 Essential SQL Interview Questions: Hire A Developer Apply As A Developer Log in
Apply as a developer
Log in
Top 3%
Why
Clients
Enterprise
Community
Blog
About Us
Questions?
Contact Us
Submit a question
Looking for experts? Check out Toptal’s SQL developers.
What does UNION do? What is the difference between UNION and UNION ALL?
View the answer →
List and explain the different types of JOIN clauses supported in ANSI-standard SQL.
Given the above query results, what will be the result of the query below?
Find top SQL developers today. Toptal can match you with the best engineers to finish your
project.
select case when null = null then 'Yup' else 'Nope' end as Result;
View the answer →
Explain your answer and also provide an alternative version of this query that will avoid the
issue that it exposes.
Id Name ReferredBy
1 John Doe NULL
2 Jane Smith NULL
3 Anne Jenkins 2
4 Eric Branford NULL
5 Pat Richards 1
6 Alice Barnes 2
Here is a query written to return the list of customers not referred by Jane Smith:
What will be the result of the query? Why? What would be a better way to write it?
Considering the database schema displayed in the SQLServer-style diagram below, write a
SQL query to return a list of all the invoices. For each invoice, show the Invoice ID, the
billing date, the customer’s name, and the name of the customer who referred that customer
(if any). The list should be ordered by billing date.
View the answer →
If there are 10 records in the Emp table and 5 records in the Dept table, how many rows will
be displayed in the result of the following SQL query:
Write a query to fetch values in table test_a that are and not in test_b without using the
NOT keyword.
Note, Oracle does not support the above INSERT syntax, so you would need this instead:
1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1
Write a SQL query to find the 10th highest employee salary from an Employee table. Explain
your answer.
(Note: You may assume that there are at least 10 records in the Employee table.)
Write a SQL query using UNION ALL (not UNION) that uses the WHERE clause to eliminate
duplicates. Why might you want to do this?
user_id username
1 John Doe
2 Jane Don
3 Alice Jones
4 Lisa Romero
Write a query to to get the list of users who took the a training lesson more than once in the
same day, grouped by user and training lesson, each ordered from the most recent lesson date
to oldest date.
What is an execution plan? When would you use it? How would you view the execution
plan?
Given a table dbo.users where the column user_id is a unique numeric identifier, how can
you efficiently select the first 100 odd user_id values from the table?
(Assume the table contains well over 100 records with odd user_id values.)
How can you select all the even number records from a table? All the odd number records?
What are the NVL and the NVL2 functions in SQL? How do they differ?
View the answer →
What is the difference between the RANK() and DENSE_RANK() functions? Provide an
example.
CustomerID CustomerName
1 Prashant Kaurav
2 Ashish Jha
3 Ankit Varma
4 Vineet Kumar
5 Rahul Kumar
Write a single SQL statement to concatenate all the customer names into the following single
semicolon-separated string:
Prashant Kaurav; Ashish Jha; Ankit Varma; Vineet Kumar; Rahul Kumar
View the answer →
Given a table Employee having columns empName and empId, what will be the result of the
SQL query below?
What will be the output of the below query, given an Employee table having 10 records?
BEGIN TRAN
TRUNCATE TABLE Employees
ROLLBACK
SELECT * FROM Employees
View the answer →
C
A
P
O
N
E
ID
----
1
2
3
4
5
(5 rows)
Table is as follows:
ID C1 C2 C3
1 Red Yellow Blue
2 NULL Red Green
3 Yellow NULL Violet
Print the rows which have ‘Yellow’ in one of the columns C1, C2, or C3, but without using
OR.
Write a query to insert/update Col2’s values to look exactly opposite to Col1’s values.
Col1 Col2
1 0
0 1
0 1
0 1
1 0
0 1
Col1 Col2
1 0
1 0
View the answer →
Now the client wants to insert a record after the identity value 7 with its identity value
starting from 10.
Imagine a single column in a table that is populated with either a single digit (0-9) or a single
character (a-z, A-Z). Write a SQL query to print ‘Fizz’ for a numeric value or ‘Buzz’ for
alphabetical value for all values in that column.
Example:
…should output:
How do you get the Nth-highest salary from the Employee table without a subquery or CTE?
x
------
2
-2
4
-4
-3
0
2
Write a single query to calculate the sum of all positive values of x and he sum of all negative
values of x.
weight
5.67
34.567
365.253
34
weight kg gms
5.67 5 67
34.567 34 567
365.253 365 253
34 34 0
View the answer →
Consider the Employee table below.
1. FROM clause
2. WHERE clause
3. GROUP BY clause
4. HAVING clause
5. SELECT clause
6. ORDER BY clause
7. TOP clause
Can we write a distributed query and get some data which is located on other server
and on Oracle Database ?
SQL Server can be lined to any server provided it has OLE-DB provider from Microsoft to
allow a link.
E.g. Oracle has a OLE-DB provider for oracle that Microsoft provides to add it as linked
server to SQL Server group.
If we drop a table, does it also drop related objects like constraints, indexes, columns,
defaults, Views and Stored Procedures ?
YES, SQL Server drops all related objects, which exists inside a table like, constraints,
indexes, columns, defaults etc. BUT dropping a table will not drop Views and Stored
Procedures as they exists outside the table.
How would you determine the time zone under which a database was operating?
What is the Difference between LEFT JOIN with WHERE clause & LEFT JOIN with
no WHERE clause ?
OUTER LEFT/RIGHT JOIN with WHERE clause can act like an INNER JOIN if not used
wisely or logically.
COALESCE accepts two or more parameters. One can apply 2 or as many parameters, but it
returns only the first non NULL parameter,
While using SQL Server Management Studio or Query Analyzer, we have an option in Menu
BAR.QUERTY >> RESULT TO >> Result to FILE
How do you prevent SQL Server from giving you informational messages during and
after a SQL statement execution?
By Mistake, Duplicate records exists in a table, how can we delete copy of a record ?
;with T as
(
select * , row_number() over (partition by Emp_ID order by Emp_ID) as
rank
from employee
)
delete
from T
where rank > 1
Pattern matching operator is LIKE and it has to used with two attributes
What’s the logical difference, if any, between the following SQL expressions?
-- Statement 1
SELECT COUNT ( * ) FROM Employees
-- Statement 2
SELECT SUM ( 1 ) FROM Employees
They’re the same unless table Employee table is empty, in which case the first yields a one-
column, one-row table containing a zero and the second yields a one-column, one-row table
"containing a null."
Could you please name different kinds of Joins available in SQL Server ?
How important do you consider cursors or while loops for a transactional database?
would like to avoid cursor in OLTP database as much as possible, Cursors are mainly only
used for maintenance or warehouse operations.
When a sub query is tied to the outer query. Mostly used in self joins.
You are supposed to work on SQL optimization and given a choice which one runs
faster, a correlated sub query or an exists?
Exists
What are the pros and cons of putting a scalar function in a queries select list or in the
where clause?
Should be avoided if possible as Scalar functions in these places make the query slow down
dramatically.
What are user defined data types and when you should go for them?
User-defined data types let you extend the base SQL Server data types by providing a
descriptive name, and format to the database. Take for example, in your database, there is a
column called Flight_Num which appears in many tables. In all these tables it should be
varchar(8). In this case you could create a user defined data type calledFlight_num_type of
varchar(8) and use it across all your tables.
This integration provide wider range of development with the help of CLR for database
server because CLR helps developers to get flexibility for developing database applications
and also provides language interoperability just like Visual C++, Visual Basic .Net and
Visual C# .Net.
The CLR helps developers to get the arrays, classes and exception handling available through
programming languages such as Visual C++ or Visual C# which is use in stored procedures,
functions and triggers for creating database application dynamically and also provide more
efficient reuse of code and faster execution of complex tasks. We particularly liked the error-
checking powers of the CLR environment, which reduces run-time errors
You are being assigned to create a complex View and you have completed that task and
that view is ready to be get pushed to production server now. you are supposed to fill a
deployment form before any change is pushed to production server.
One of the Filed in that deployment form asked, “Expected Storage requirement”.
What all factors you will consider to calculate storage requirement for that view ?
Very tricky, View, doesn’t takes space in Database, Views are virtual tables. Storage is
required to store Index, incase you are developing a indexed view.
Clustered Index:- A Clustered index is a special type of index that reorders the way records in
the table are physically stored. Therefore table may have only one clustered index.Non-
Clustered Index:- 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 in the disk. The leaf nodes
of a non-clustered index does not consists of the data pages. instead the leaf node contains
index rows.
Write down the general syntax for a SELECT statements covering all the options.
Here’s the basic syntax: (Also checkout SELECT in books online for advanced syntax).
SELECT select_list
[INTO new_table_]
FROM table_source
[WHERE search_condition]
[GROUP BY group_by__expression]
[HAVING search_condition]
[ORDER BY order__expression [ASC | DESC] ]
Joins are used in queries to explain how different tables are related. Joins also let you select
data from a table depending upon data from another table.
Types of joins:
INNER JOINs,
OUTER JOINs,
CROSS JOINs
For more information see pages from books online titled: "Join Fundamentals" and "Using
Joins".
OSQL is command line tool which is used execute query and display the result same a query
analyzer but everything is in command prompt.
OSQL is command line tool which executes query and display the result same a query
analyzer but query analyzer is graphical and OSQL is a command line tool. OSQL is quite
useful for batch processing or executing remote queries.
CASCADE allows deletions or updates of key values to cascade through the tables defined to
have foreign key relationships that can be traced back to the table on which the modification
is performed.
What are some of the join algorithms used when SQL Server joins tables.
The MAGIC tables are automatically created and dropped, in case you use TRIGGERS. SQL
Server has two magic tables named, INSERTED and DELETED
These are mantained by SQL server for there Internal processing. When we use update insert
or delete on tables these magic tables are used.These are not physical tables but are Internal
tables.When ever we use insert statement is fired the Inserted table is populated with newly
inserted Row and when ever delete statement is fired the Deleted table is populated with the
delete
d row.But in case of update statement is fired both Inserted and Deleted table used for records
the Original row before updation get store in Deleted table and new row Updated get store in
Inserted table.
YES, we can disable a single trigger on the database by using “DISABLE TRIGGER
triggerName ON <>”
we also have an option to disable all the trigger by using, “DISABLE Trigger ALL ON ALL
SERVER”
Why you need indexing? where that is Stored and what you mean by schema object?
For what purpose we are using view?
We can’t create an Index on Index.. Index is stoed in user_index table. Every object that has
been created on Schema is Schema Object like Table, View etc. If we want to share the
particular data to various users we have to use the virtual table for the Base table. So that is a
view.
Indexing is used for faster search or to retrieve data faster from various table. Schema
containing set of tables, basically schema means logical separation of the database. View is
crated for faster retrieval of data. It’s customized virtual table. we can create a single view of
multiple tables. Only the drawback is..view needs to be get refreshed for retrieving updated
data.
Union will remove the duplicate rows from the result set while Union all does’nt.
Which system table contains information on constraints on all the tables created ?
USER_CONSTRAINTS,
system table contains information on constraints on all the tables created
1. Cross Join A cross join that does not have a WHERE clause produces the Cartesian
product of the tables involved in the join. The size of a Cartesian product result set is
the number of rows in the first table multiplied by the number of rows in the second
table. The common example is when company wants to combine each product with a
pricing table to analyze each product at each price.
2. Inner Join A join that displays only the rows that have a match in both joined tables
is known as inner Join. This is the default type of join in the Query and View
Designer.
3. Outer Join A join that includes rows even if they do not have related rows in the
joined table is an Outer Join. You can create three different outer join to specify the
unmatched rows to be included:
1. Left Outer Join: In Left Outer Join all rows in the first-named table i.e. "left"
table, which appears leftmost in the JOIN clause are included. Unmatched
rows in the right table do not appear.
2. Right Outer Join: In Right Outer Join all rows in the second-named table i.e.
"right" table, which appears rightmost in the JOIN clause are included.
Unmatched rows in the left table are not included.
3. Full Outer Join: In Full Outer Join all rows in all joined tables are included,
whether they are matched or not.
4. Self Join This is a particular case when one table joins to itself, with one or two
aliases to avoid confusion. A self join can be of any type, as long as the joined tables
are the same. A self join is rather unique in that it involves a relationship with only
one table. The common example is when company has a hierarchal reporting structure
whereby one member of staff reports to another. Self Join can be Outer Join or Inner
Join.
What is Data-Warehousing?
1. Subject-oriented, meaning that the data in the database is organized so that all the
data elements relating to the same real-world event or object are linked together;
2. Time-variant, meaning that the changes to the data in the database are tracked and
recorded so that reports can be produced showing changes over time;
3. Non-volatile, meaning that data in the database is never over-written or deleted, once
committed, the data is static, read-only, but retained for future reporting.
4. Integrated, meaning that the database contains data from most or all of an
organization’s operational applications, and that this data is made consistent.
A live lock is one, where a request for an exclusive lock is repeatedly denied because a series
of overlapping shared locks keeps interfering. SQL Server detects the situation after four
denials and refuses further shared locks. A live lock also occurs when read transactions
monopolize a table or page, forcing a write transaction to wait indefinitely.
When SQL Server executes a statement with nested subqueries, it always executes the
innermost query first. This query passes its results to the next query and so on until it reaches
the outermost query. It is the outermost query that returns a result set.
YES, to delete a column in a table, use ALTER TABLE table_name DROP COLUMN
column_name
Which statement do you use to eliminate padded spaces between the month and day
values in a function TO_CHAR(SYSDATE,’Month, DD, YYYY’) ?
To remove padded spaces, you use the "fm" prefix before the date element that contains the
spaces. TO_CHAR(SYSDATE,’fmMonth DD, YYYY’)
Which operator do you use to return all of the rows from one query except rows are
returned in a second query?
You use the EXCEPT operator to return all rows from one query except where duplicate
rows are found in a second query. The UNION operator returns all rows from both queries
minus duplicates. The UNION ALL operator returns all rows from both queries including
duplicates. The INTERSECT operator returns only those rows that exist in both queries.
The clauses of the subselect are processed in the following sequence (DB2): 1. FROM clause
2. WHERE clause 3. GROUP BY clause 4. HAVING clause 5. SELECT clause 6. ORDER
BY clause 7. FETCH FIRST clause
sp_depends system stored procedure or query the sysdepends system table to return a list of
objects that a user-defined function depends upon
A query first takes the lowest level lock possible with the smallest footprint (row-level).
When too many rows are locked (requiring too much RAM) the lock is escalated to a range
or page lock. If too many pages are locked, it may escalate to a table lock.
What are the main differences between #temp tables and @table variables and which
one is preferred ?
When we done operation on SQL SERVER that is not commited directly to the database.All
operation must be logged in to Transaction Log files after that they should be done on to the
main database.CheckPoint are the point which alert Sql Server to save all the data to main
database if no check point is there then log files get full we can use Checkpoint command to
commit all data in the SQL SERVER.When we stop the SQL Server it will take long time
because Checkpoint is also fired.
OPENXML parses the XML data in SQL Server in an efficient manner. It’s primary ability is
to insert XML data to the DB.
YES, we can store Videos inside SQL Server by using FILESTREAM datatype, which was
introduced in SQL Server 2008.
YES, while creating stored procedure we can use WITH ENCRYPTION which will convert
the original text of the CREATE PROCEDURE statement to an encrypted format.
What are included columns when we talk about SQL Server indexing?
Indexed with included columns were developed in SQL Server 2005 that assists in covering
queries. Indexes with Included Columns are non clustered indexes that
have the following benefits:
Columns defined in the include statement, called non-key columns, are not counted in
the
as a non-key column.
A maximum of 1023 additional columns can be used as non-key columns.
What is an execution plan? How would you view the execution plan?
An execution plan is basically a road map that graphically or textually shows the data
retrieval methods chosen by the SQL Server query optimizer for a stored procedure or ad-hoc
query and is a very useful tool for a developer to understand the performance characteristics
of a query or stored procedure since the plan is the one that SQL Server will place in its
cache and use to execute the stored procedure or query. From within Query Analyzer is an
option called "Show Execution Plan" (located on the Query drop-down menu). If this option
is turned on it will display query execution plan in separate window when query is ran again.
MINUS – returns all distinct rows selected by the first query but not by the second.
UNION ALL - returns all rows selected by either query, including all duplicates
INTERVIEWS
BOOKS
NEWS
EVENTS
CAREER
JOBS
TRAINING
MORE
Interview Questions For 2 Years Experience
in SQL and C#
Rasmita Dash
May 29 2015
Article
35
47
783.3k
facebook
twitter
linkedIn
google Plus
Reddit
o Email
o Bookmark
o Other Artcile
Expand
I appeared for an interview that was for 2 years experience and had 4 technical rounds. Here
my purpose is to share the questions that I encountered. However, I have given brief answers
just for reference.
1. What is a Database?
A database is a collection of information in an organized form for faster and better access,
storage and manipulation. It can also be defined as a collection of tables, schema, views and
other database objects.
8. What is DBMS?
Database Management System is a collection of programs that enables a user to store,
retrieve, update and delete information from a database.
9. What is RDBMS?
RDBMS stands for Relational Database Management System. RDBMS is a database
management system (DBMS) that is based on the relational model. Data from relational
database can be accessed using Structured Query Language (SQL)
10. What are the popular Database Management Systems in the IT Industry?
Oracle, MySQL, Microsoft SQL Server, PostgreSQL, Sybase, MongoDB, DB2, and
Microsoft Access etc.,
11. What is SQL?
SQL Overview: SQL stands for Structured Query Language. It is an American National
Standard Institute (ANSI) standard. It is a standard language for accessing and manipulating
databases. Using SQL, some of the action we could do are to create databases, tables, stored
procedures (SP’s), execute queries, retrieve, insert, update, delete data against a database.
INNER JOIN
LEFT JOIN
RIGHT JOIN
OUTER JOIN
The short answer is no, a table is not allowed to contain multiple primary keys but it allows to
have one composite primary key consisting of two or more columns.
35. What is the difference between UNIQUE and PRIMARY KEY constraints?
There should be only one PRIMARY KEY in a table whereas there can be any number of
UNIQUE Keys.
PRIMARY KEY doesn’t allow NULL values whereas Unique key allows NULL values.
37. What is the difference between NULL value, Zero, and Blank space?
As I mentioned earlier, Null value is field with no value which is different from zero value
and blank space.
Null value is a field with no value.
Zero is a number
Blank space is the value we provide. The ASCII value of space is CHAR(32).
E.g. ‘Age’ field should contain only the value greater than 18.
46. What are the possible values that can be stored in a BOOLEAN data field?
TRUE and FALSE
47. What is the largest value that can be stored in a BYTE data field?
The largest number that can be represented in a single byte is 11111111 or 255. The number
of possible values is 256 (i.e. 255 (the largest possible value) plus 1 (zero), or 28).
1. Arithmetic Operators
2. Comparison Operators
3. Logical Operators
Atomicity
Consistency
Isolation
Durability
52. What is the difference between Delete, Truncate and Drop command?
The difference between the Delete, Truncate and Drop command is
Delete command is a DML command, it is used to delete rows from a table. It can be
rolled back.
Truncate is a DDL command, it is used to delete all the rows from the table and free
the space containing the table. It cant be rolled back.
Drop is a DDL command, it removes the complete data along with the table
structure(unlike truncate command that removes only the rows). All the tables’ rows,
indexes, and privileges will also be removed.
DELETE TRUNCATE
Delete statement is used to delete Truncate statement is used to delete all the rows from
rows from a table. It can be rolled the table and free the space containing the table. It
back. cant be rolled back.
We can use WHERE condition in
We cant use WHERE condition in TRUNCATE
DELETE statement and can delete
statement. So we cant delete required rows alone
required rows
We can delete specific rows using We can only delete all the rows at a time using
DELETE TRUNCATE
Delete is a DML command Truncate is a DDL command
Delete maintains log and performance Truncate maintains minimal log and performance wise
is slower than Truncate faster
We need DELETE permission on We need at least ALTER permission on the table to
DELETE TRUNCATE
Table to use DELETE command use TRUNCATE command
54. What is the difference between Union and Union All command?
This is one of the tricky SQL Interview Questions. Interviewer may ask you this question in
another way as what are the advantages of Union All over Union.
Both Union and Union All concatenate the result of two tables but the way these two queries
handle duplicates are different.
Union: It omits duplicate records and returns only distinct result set of two or more select
statements.
Union All: It returns all the rows including duplicates in the result set of different select
statements.
Performance wise Union All is faster than Union, Since Union All doesn’t remove duplicates.
Union query checks the duplicate values which consumes some time to remove the duplicate
records.
Assume: Table1 has 10 records, Table2 has 10 records. Last record from both the tables are
same.
Data type of all the columns in the two tables should be same.
55. What is the difference between Having and Where clause?
Where clause is used to fetch data from a database that specifies particular criteria whereas a
Having clause is used along with ‘GROUP BY’ to fetch data that meets particular criteria
specified by the Aggregate functions. Where clause cannot be used with Aggregate functions,
but the Having clause can.
58. How to add new Employee details in an Employee_Details table with the following
details
Employee_Name: John, Salary: 5500, Age: 29?
60. How to change a value of the field ‘Salary’ as 7500 for an Employee_Name ‘John’ in
a table Employee_Details?
61. Write an SQL Query to select all records from the table?
USE TestDB
GO
SELECT * FROM sys.Tables
GO
1 USE TestDB
2 GO
3 SELECT * FROM sys.Tables
4 GO
63. Define SQL Delete statement.
The SQL Delete statement is used to delete records from a table.
64. Write the command to remove all Players named Sachin from the Players table.
65. How to fetch values from TestTable1 that are not in TestTable2 without using NOT
keyword?
--------------
| TestTable1 |
--------------
| 11 |
1 --------------
2 | TestTable1 |
3 --------------
4 | 11 |
5 | 12 |
6 | 13 |
7 | 14 |
8 --------------
--------------
| TestTable2 |
--------------
| 11 |
1 --------------
2 | TestTable2 |
3 --------------
4 | 11 |
5 | 12 |
6 --------------
By using the except keyword
66. How to get each name only once from an employee table?
By using the DISTINCT keyword, we could get each name only once.
SELECT GetDate();
1 SELECT GetDate();
70. Write an SQL Query to find an Employee_Name whose Salary is equal or greater
than 5000 from the below table Employee_Details.
| Employee_Name | Salary|
-----------------------------
| John | 2500 |
| Emma | 3500 |
1 | Employee_Name | Salary|
2 -----------------------------
3 | John | 2500 |
4 | Emma | 3500 |
5 | Mark | 5500 |
6 | Anne | 6500 |
7 -----------------------------
Syntax:
Output:
| Employee_Name | Salary|
-----------------------------
| Mark | 5500 |
| Anne | 6500 |
1 | Employee_Name | Salary|
2 -----------------------------
3 | Mark | 5500 |
4 | Anne | 6500 |
5 -----------------------------
71. Write an SQL Query to find list of Employee_Name start with ‘E’ from the below
table
| Employee_Name | Salary|
-----------------------------
| John | 2500 |
| Emma | 3500 |
1 | Employee_Name | Salary|
2 -----------------------------
3 | John | 2500 |
4 | Emma | 3500 |
5 | Mark | 5500 |
6 | Anne | 6500 |
7 -----------------------------
Syntax:
SELECT * FROM Employee_Deta
1 | Employee_Name | Salary|
2 -----------------------------
3 | Emma | 3500 |
4 -----------------------------
72. Write SQL SELECT query that returns the FirstName and LastName from
Employee_Details table.
SELECT FirstName, LastName F
1 sp_rename OldTableName,NewTableName
2 sp_rename 'TableName.OldColumnName', 'NewColumnName'
74. How to select all the even number records from a table?
To select all the even number records from a table:
Select * from table w here id % 2
77. Can you display the result from the below table TestTable based on the criteria M,m
as M and F, f as F and Null as N and g, k, I as U
1 | Gender |
2 ------------
3 | M |
4 | F |
5 | NULL |
6 | m |
7 | f |
8 | g |
9 | H |
10 | i |
11 ------------
SELECT Gender,
case
w hen Gender='i' then 'U'
w hen Gender='g' then 'U'
1 SELECT Gender,
2 case
3 when Gender='i' then 'U'
4 when Gender='g' then 'U'
5 when Gender='H' then 'U'
6 when Gender='NULL' then 'N'
7 else upper(Gender)
8 end as newgender from TestTable GROUP BY Gender
1 select case when null = null then 'True' else 'False' end as Result;
This query returns “False”. In the above question, we could see null = null is not the proper
way to compare a null value. To compare a value with null, we use IS operator in SQL.
1 select case when null is null then 'True' else 'False' end as Result;
select case when null is null then 'Queries In SQL Server' else 'Queries In MySQL' end as
1
Result;
80. How do you update F as M and M as F from the below table TestTable?
| Name | Gender |
------------------------
| John | M |
| Emma | F |
1 | Name | Gender |
2 ------------------------
3 | John | M |
4 | Emma | F |
5 | Mark | M |
6 | Anne | F |
7 ------------------------
1 UPDATE TestTable SET Gender = CASE Gender WHEN 'F' THEN 'M' ELSE 'F' END
83. What is the difference between NVL function, IFNULL function, and ISNULL
function?
These three functions work in the same way. These functions are used to replace NULL value
with another value. Oracle developers use NVL function, MySQL developers use IFNULL
function and SQL Server developers use ISNULL function.
Assume, some of the values in a column are NULL.
If you run below statement, you will get result as NULL
Suppose any of the value in col3 is NULL then as I said your result will be NULL.
To overcome this we use NVL() function, IFNULL() function, ISNULL() Function.
ORACLE:
MySQL:
SQL Server:
Final words, Bookmark this post “SQL Interview Questions For Testers” for future reference.
After reading this post “SQL Interview Questions”, if you find that we missed some
important SQL Server Interview Questions, please comment below we would try to include
those with answers.