SQL
SQL
6 Which clause is used to see the output of query in ascending or descending order?
Ans.
7 Which clause is used to eliminate the duplicate rows from output?
Ans.
8 What is the minimum number of column required in MySQL to create table?
Ans.
9 Which command is used to remove the table from database?
Ans.
10 Which command is used to add new record in table?
Ans.
11 Which option of ORDER BY clause is used to arrange the output in descending order?
Ans.
12 Which command is used to change the existing information of table?
Ans.
13 Raj is a database programmer, He has to write the query from EMPLOYEE table to search for
the employee whose name begins from letter „R‟, for this he has written the query as:
SELECT * FROM EMPLOYEE WHERE NAME=‟R%‟;
But the query is not producing the correct output, help Raj and correct the query so that he
gets the desired output.
Ans.
14 Raj is a database programmer, He has to write the query from EMPLOYEE table to search for
the employee who are not getting any commission, for this he has written the query as:
SELECT * FROM EMPLOYEE WHERE commission=null;
But the query is not producing the correct output, help Raj and correct the query so that he
gets the desired output.
Ans.
15 Raj is a database programmer, has to write the query from EMPLOYEE table to search for the
employee who are working in „Sales‟ or „IT‟ department, for this he has written the query as:
SELECT * FROM EMPLOYEE WHERE department=‟Sales‟ or „IT‟;
But the query is not producing the correct output, help Raj and correct the query so that he
gets the desired output.
Ans.
1|Page VB/WS/2023-24
16 The following query is producing an error. Identify the error and also write the correct query.
SELECT * FROM EMP ORDER BY NAME WHERE SALARY>=5000;
Ans.
17 If Table Sales contains 5 records and Raj executed the following queries; find out the output
of both the query.
(i) Select 100+200 from dual;
(ii) Select 100+200 from Sales;
Ans.
19 Observe the given Table TEACHER and give the output of question (i) and (ii)
TEACHER_CODE TEACHER_NAME DOJ
T001 ANAND 2001-01-30
T002 AMIT 2007-09-05
T003 ANKIT 2007-09-20
T004 BALBIR 2010-02-15
T005 JASBIR 2011-01-20
T006 KULBIR 2008-07-11
(i) SELECT TEACHER_NAME,DOJ FROM TEACHER WHERE TEACHER_NAME LIKE „%I%‟
(ii) SELECT * FROM TEACHER WHERE DOJ LIKE „%-09-%‟;
Ans
20 Which SQL function is used to get the average value of any column?
Ans.
21 What is the difference between COUNT() and COUNT(*) function
Ans.
2|Page VB/WS/2023-24
23 Query to delete all record of table without deleting the table:
a. DELETE TABLE TABLE_NAME
b. DELETE FROM TABLE_NAME
c. DROP TABLE TABLE_NAME
d. DELETE TABLE FROM TABLE_NAME
Ans.
24 Identify the wrong statement about UPDATE command
a. If WHERE clause is missing all the record in table will be updated
b. Only one record can be updated at a time using WHERE clause
c. Multiple records can be updated at a time using WHERE clause
d. None of the above
Ans.
25 Identify the correct statement(s) to drop a column from table
a. DELETE COLUMN COLUMN_NAME
b. DROP COLUMN COLUMN_NAME
c. ALTER TABLE TABLE_NAME DROP COLUMN COLUMN_NAME
d. ALTER TABLE TABLE_NAME DROP COLUMN_NAME
Ans.
26 Suppose a table BOOK contain columns (BNO, BNAME, AUTHOR, PUBLISHER), Raj is
assigned a task to see the list of publishers, when he executed the query as:
SELECT PUBLISHER FROM BOOK;
He noticed that the same publisher name is repeated in query output. What could be possible
solution to get publisher name uniquely? Rewrite the following query to fetch unique
publisher names from table.
Ans.
27 HOTS
Consider a database table T containing two columns X and Y each of type integer. After the
creation of the table, one record (X=1, Y=1) is inserted in the table.
Let MX and MY denote the respective maximum values of X and Y among all records in the
table at any point in time. Using MX and MY, new records are inserted in the table 128 times
with X and Y values being MX+1, 2*MY+1 respectively. It may be noted that each time after
the insertion, values of MX and MY change. What will be the output of the following SQL
query after the steps mentioned above are carried out?
SELECT Y FROM T WHERE X = 7
A. 127
B. 255
C. 129
D. 257
Ans.
28 Which SQL function is used to find the highest and lowest value of numeric and date type
column?
Ans.
29 What is the default order of sorting using ORDER BY?
Ans.
30 What is the difference between CHAR and VARCHAR?
Ans.
3|Page VB/WS/2023-24
31 Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii) which are based on tables
TABLE: TRANSACT
TRNO ANO AMOUNT TYPE DOT
T001 101 2500 Withdraw 2017-12-21
T002 103 3000 Deposit 2017-06-01
T003 102 2000 Withdraw 2017-05-12
T004 103 1000 Deposit 2017-10-22
T005 102 12000 Deposit 2017-11-06
(i) To display details of all transactions of TYPE Withdraw from TRANSACT table
(ii) To display ANO and AMOUNT of all Deposit and Withdrawals done in month of
„May‟ 2017 from table TRANSACT
(iii) To display first date of transaction (DOT) from table TRANSACT for Account having
ANO as 102
(iv) To display ANO, ANAME, AMOUNT and DOT of those persons from ACCOUNT and
TRANSACT table who have done transaction less than or equal to 3000
(v) SELECT ANO, ANAME FROM ACCOUNT
WHERE ADDRESS NOT IN ('CHENNAI', 'BANGALORE');
(vi) SELECT DISTINCT ANO FROM TRANSACT
(vii) SELECT ANO, COUNT(*), MIN(AMOUNT) FROM TRANSACT
GROUP BY ANO HAVING COUNT(*)> 1
(viii) SELECT COUNT(*), SUM(AMOUNT) FROM TRANSACT
WHERE DOT <= '2017-10-01'
Ans.
4|Page VB/WS/2023-24
32 Consider the following tables EMP and SALGRADE, write the query for (i) to (vi) and output
for (vii) to (x)
TABLE: EMPLOYEE
ECODE NAME DESIG SGRADE DOJ DOB
101 Vikrant Executive S03 2003-03-23 1980-01-13
102 Ravi Head-IT S02 2010-02-12 1987-07-22
103 John Cena Receptionist S03 2009-06-24 1983-02-24
105 Azhar Ansari GM S02 2009-08-11 1984-03-03
108 Priyam Sen CEO S01 2004-12-29 1982-01-19
TABLE: SALGRADE
SGRADE SALARY HRA
S01 56000 18000
S02 32000 12000
S03 24000 8000
(i) To display details of all employee in descending order of their DOJ
(ii) To display NAME AND DESIG of those employees whose sgrade is either „S02‟ or
„S03‟
(iii) To display NAME, DESIG, SGRADE of those employee who joined in the year 2009
(iv) To display all SGRADE, ANNUAL_SALARY from table SALGRADE [where
ANNUAL_SALARY = SALARY*12]
(v) To display number of employee working in each SALGRADE from table EMPLOYEE
(vi) To display NAME, DESIG, SALARY, HRA from tables EMPLOYEE and SALGRADE
where SALARY is less than 50000
(vii) Select MIN(DOJ), MAX(DOB) from employee;
(viii) Select SGrade,Salary+HRA from SalGrade where Sgrade=‟S02‟
(ix) Select count(distinct sgrade) from employee
(x) Select sum(salary), avg(salary) from salgrade
Ans (i)
5|Page VB/WS/2023-24
(i) To display details of all Trains which starts from New Delhi
(ii) To display PNR, PNAME, GENDER and AGE of all passengers whose AGE is below
50
(iii) To display total numbers of MALE and FEMALE passengers
(iv) To display records of all passengers travelling in trains whose TNO is 12015
(v) SELECT MAX(TRAVELDATE),MIN(TRAVELDATE) FROM PASSENGERS WHERE
GENDER=‟FEMALE‟;
(vi) SELECT END, COUNT(*) FROM TRAINS GROUP BY END HAVING COUNT(*)>1;
(vii) SELECT DISTINCT TRAVELDATE FROM PASSENGERS;
6|Page VB/WS/2023-24
(viii) SELECT TNAME, PNAME FROM TRAINS T, PASSENGERS P WHERE T.TNO=P.TNO
AND AGE BETWEEN 50 AND 60
7|Page VB/WS/2023-24