Computer Knowledge

Database and SQL

4,213 Questions

Master structured query language commands, database joins, table constraints, and alias generation. This section covers relational database management concepts and query outputs essential for technical aptitude. These technical questions feature prominently in banking IT officer exams and computer knowledge sections.

SQL queries and aliasesDatabase table constraintsDatabase joins and transformationsStored procedures and functions

Database and SQL Questions

Multiple choice
  1. select First_name, Last_name from employee1 where employee1.Job_Id=job.Job_ID;

  2. select First_name, Last_name from employee1 e, job j where e.employee_Id=j.Job_ID;

  3. select First_name, Last_name from employee1 e, job j where e.Job_Id=j.Job_ID;

  4. select First_name, Last_name from employee1 e, job j where e.Manager_id=j.Job_ID;

  5. none of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This is the correct query for the desired result.

Multiple choice
  1. Select item, max(price), min(price) from items_ordered group by item where max(price)>1500

  2. Select max(price), min(price) from items_ordered group by item having max(price)>1500

  3. Select item, max(price), min(price) from items_ordered group by item having max(price)>1500

  4. Select item, max(price), min(price) from items_ordered group by item having count(price)>1500

  5. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This is the correct SQL statement to display the desire output.

Multiple choice
  1. SELECT avg(price) FROM items_ordered WHERE order_date '%Jun%';

  2. SELECT avg(price) FROM items_ordered WHERE order_date LIKE '%Jun%';

  3. SELECT avg(price) FROM items_ordered WHERE order_date LIKE '%Jun';

  4. SELECT avg(price) FROM items_ordered WHERE order_date LIKE 'Jun';

  5. None of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

This is the correct query for the desired output.

Multiple choice
  1. SELECT MAX(SAL) FROM Employee GROUP BY DEPTNO, JOB

  2. SELECT DEPTNO, MAX(SAL) FROM Employee GROUP BY DEPTNO, JOB

  3. SELECT DEPTNO, JOB, MAX(SAL) FROM Employee GROUP BY DEPTNO, JOB

  4. SELECT JOB, MAX(SAL) FROM Employee GROUP BY DEPTNO, JOB

  5. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This is the correct sql query for the desired output.

Multiple choice
  1. SELECT firstname, city, state FROM customers WHERE state LIKE ('Arizona', 'Washington', 'Oklahoma', 'Colorado');

  2. SELECT firstname, city, state FROM customers WHERE state ('Arizona', 'Washington', 'Oklahoma', 'Colorado');

  3. SELECT firstname, city, state FROM customersAND state LIKE('Arizona', 'Washington', 'Oklahoma', 'Colorado');

  4. SELECT firstname, city, state FROM customers WHERE state IN ('Arizona', 'Washington', 'Oklahoma', 'Colorado');

  5. None of the above

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This is the correct query for the desired result.

Multiple choice
  1. SELECT DEPTNO, JOB FROM EMP GROUP BY DEPTNO

  2. SELECT DEPTNO FROM EMP WHERE JOB=’CLERK’ GROUP BY DEPTNO

  3. SELECT DEPTNO, COUNT(*) FROM EMP WHERE JOB=’CLERK’ GROUP BY DEPTNO

  4. SELECT DEPTNO, COUNT() FROM EMP WHERE JOB=’CLERK’ GROUP BY DEPTNO

  5. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This is the correct query for the desired result.

Multiple choice
  1. SELECT MAX(SAL) FROM EMP GROUP BY DEPTNO

  2. SELECT * FROM EMP WHERE SAL>1 GROUP BY DEPTNO

  3. SELECT * FROM EMP WHERE SAL IN(SELECT SAL FROM EMP GROUP BY DEPTNO)

  4. SELECT * FROM EMP WHERE SAL IN(SELECT MAX(SAL) FROM EMP GROUP BY DEPTNO)

  5. None of the above

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This is a correct syntax for desired output.

Multiple choice
  1. SELECT item FROM items_ordered WHERE price > 1500 ORDER BY price ASC;

  2. SELECT price FROM items_ordered WHERE price > 1500 ORDER BY price ASC;

  3. SELECT item, price FROM items_ordered WHERE price > 1500 ORDER BY item ASC;

  4. SELECT item, price FROM items_ordered WHERE price > 1500 ORDER BY price ASC;

  5. None of the above

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

This is the correct query for desired result.

Multiple choice
  1. SELECT * FROM EMP WHERE SAL>1

  2. SELECT * FROM EMP WHERE SAL>0

  3. SELECT * FROM EMP WHERE SAL IN(SELECT COUNT(DISTINCT SAL) FROM EMP )

  4. SELECT * FROM EMP E WHERE 0=(SELECT COUNT( SAL) FROM EMP WHERE SAL>E.SAL)

  5. SELECT * FROM EMP E WHERE 0=(SELECT COUNT(DISTINCT SAL) FROM EMP WHERE SAL>E.SAL)

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

This is the correct syntax for the desired result.

Multiple choice
  1. SELECT COUNT(DISTINCT SAL) FROM EMP E WHERE SAL>E.SAL

  2. SELECT MAX(DISTINCT SAL) FROM EMP E WHERE SAL>E.SAL

  3. SELECT * FROM EMP E WHERE 1=(SELECT COUNT(DISTINCT SAL) FROM EMP WHERE SAL>E.SAL)

  4. SELECT * FROM EMP E WHERE 0=(SELECT COUNT(DISTINCT SAL) FROM EMP WHERE SAL>E.SAL)

  5. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This is the correct query as we need second highest salary so we need to query as the salary less than the first employee.

Multiple choice
  1. SELECT * FROM DEPT WHERE DEPTNO !=(SELECT DISTINCT DEPTNO FROM EMP)

  2. SELECT * FROM DEPT WHERE DEPTNO NOT IN(SELECT DISTINCT DEPTNO FROM EMP)

  3. SELECT * FROM DEPT WHERE DEPTNO NOT IN(SELECT DEPTNO FROM EMP)

  4. SELECT * FROM DEPT WHERE DEPTNO NOT IN(SELECT DISTINCT DEPTNO FROM EMP WHERE EMP.DEPTNO=DEPT.DEPTNO )

  5. None of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

This is the correct syntax as it will show the those departments from the employee table that do not belongs to working employees. Here we used Distinct keyword to escape those results.

Multiple choice
  1. SELECT customerid FROM customers GROUP BY state;

  2. SELECT customerid, count(state) FROM customers GROUP BY state;

  3. SELECT state, count(state) FROM customers GROUP BY state;

  4. SELECT * FROM customers GROUP BY state;

  5. SELECT count(state) FROM customers GROUP BY state;

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This is the correct syntax as this will display the result for the unique state for all the customers.

Multiple choice
  1. SELECT * FROM EMP WHERE DEPTNO IN(SELECT DISTINCT DEPTNO FROM EMP)

  2. SELECT * FROM DEPT WHERE DEPTNO IN(SELECT DISTINCT DEPTNO FROM EMP)

  3. SELECT * FROM DEPT WHERE EXISTS(SELECT DEPTNO FROM EMP WHERE EMP.DEPTNO=DEPT.DEPTNO)

  4. Both (2) and (3)

  5. None of the above

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

Both are the correct syntax for the correct output.

Multiple choice
  1. 1

  2. 2

  3. 3

  4. 4

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

There are three parts in a PL/SQL program. They are - declaration section (where the variables are declared), begin section (where executable code is written) and exception section (where the exceptions are handled). The declaration and exception sections are optional but the begin part is compulsory. A PL/SQL program ends with an 'end' statement.