Professional Documents
Culture Documents
SQL Interview Questions and Answers
SQL Interview Questions and Answers
Q. What is SQL?
Q. What is DB2?
DB2 is the short name used for DATABASE 2. It is relational
database product developed by IBM. in 1983
Q. What is DB/400?
It is one of the flavors of IBM DB2
Q. What are the categories of operators available in
SQL?
• Arithmetic operators
• Comparison operators
• Logical operators
Operator Description
+ (Addition ) Adds values
- (Subtraction) Subtracts Right side value from Left side
value
* Multiplies values on either side of the operator
(Multiplication)
/ (Division) Divides left hand operand by right hand
operand
% (Modulus) Divides left hand operand by right hand
operand and returns remainder
For example x = 1, y= 2
Operator Example
= (x = y) is False
!= (x != y) is True.
<> (x <> y) is true.
> (x > y) is False
< (x < y) is True
>= (x >= y) is False
<= (x <= y) is True
!< (x !< y) is False
!> (x !> y) is True.
Note: Comparison Operators return Logical Results
Operator Description
-------- -----------
NOT Returns TRUE if the following condition is
FALSE. Returns FALSE if it is TRUE.
AND Returns TRUE if both component conditions are
TRUE. Returns FALSE if either is FALSE
OR Returns TRUE if either component condition is
TRUE. Returns FALSE if both are FALSE.
Syntax:
Example:
Syntax:
Example:
Syntax:
USE DatabaseName;
Example:
Syntax:
Syntax:
Syntax:
Or
= Equal
<> or != Not equal
USER_TAB_PRIVS_MADE, USER_TAB_PRIVS_RECD
USER_CONSTRAINTS.
True.
START or @.
RUN.
REVOKE.
MONTHS_BETWEEN.
LIKE operator.
IS NULL operator.
FLOOR.
Explanation :
Explanation:
To copy only the structure, the WHERE clause of the SELECT
command should contain a FALSE statement as in the
following.
1200.
Outer Join - Joining two tables in such a way that query can
also retrieve rows that do not have corresponding join value
in the other table.
SUBSTR (String1 n, m)
SUBSTR returns a character string of size m in string1,
starting from n-th position of string1.
SQL Queries
LOCATION
Location_ID Regional_Group
122 NEW YORK
123 DALLAS
124 CHICAGO
167 BOSTON
DEPARTMENT
Department_ID Name Location_ID
10 ACCOUNTING 122
20 RESEARCH 124
30 SALES 123
40 OPERATIONS 167
JOB
Job_ID Function
667 CLERK
668 STAFF
669 ANALYST
670 SALESPERSON
671 MANAGER
672 PRESIDENT
EMPLOYEE
EMPLOYEE_ID LAST_NAME FIRST_NAME MIDDLE_NAME JOB_ID MANA
7369 SMITH JOHN Q 667 7
7499 ALLEN KEVIN J 670 7
7505 DOYLE JEAN K 671 7
7506 DENNIS LYNN S 671 7
7507 BAKER LESLIE D 671 7
7521 WARK CYNTHIA D 670 7
Simple Queries:
Where Conditions:
Order By Clause:
Sub-Queries
43. List out the employees who earn more than every
employee in department 30.
44. List out the employees who earn more than the
lowest salary in department 30.
45. Find out whose department has not employees.
46. Find out which department does not have any
employees.
JOINS
Simple join
Self Join:
Outer Join:
Set Operators: