Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
87 views4 pages

Simple Queries in SQL Chapter - 14 Type A: Very Short Answer Questions

This document provides examples of SQL queries and concepts. It contains two sections: 1. Very short answer questions about SQL concepts like data types, fields, comparison operators, and functions. 2. Short answer questions involving writing basic SELECT queries on sample tables to retrieve, filter, sort, and calculate specific fields. The questions cover concepts like WHERE, LIKE, BETWEEN, NULL, ORDER BY, and arithmetic operators.

Uploaded by

Som
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views4 pages

Simple Queries in SQL Chapter - 14 Type A: Very Short Answer Questions

This document provides examples of SQL queries and concepts. It contains two sections: 1. Very short answer questions about SQL concepts like data types, fields, comparison operators, and functions. 2. Short answer questions involving writing basic SELECT queries on sample tables to retrieve, filter, sort, and calculate specific fields. The questions cover concepts like WHERE, LIKE, BETWEEN, NULL, ORDER BY, and arithmetic operators.

Uploaded by

Som
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Simple Queries in SQL

Chapter - 14
Type A: Very Short Answer Questions
1 Maximum how many characters can be stored in a (i) text literal (ii) numeric literal?
Ans. In MySQL 5.1 text literal can store maximum of 4000 bytes and in numeric literal maximum of 53 digits of percision
can store. But in newer version of MySQL this figure is increased.
2 What is a datatype? Name some datatype available in MySQL.
Ans. Datatypes are means to identify the type of data and associated operations for handling. A value’s datatype
associated a fixed set of properties with the value. In MySQL there various datatypes for example – int, decimal,
char, varchar, date etc.
3 What are fixed length fields? What are variable length fields?
Ans. Fixed length fields – fields whose length (maximum number of data) is fixed and occupy the maximum number of
length even if maximum number of data is not filled in field.
Variable length fields – here every data element in the field is determined separately and the number of characters
in data element becomes its field length. It does not occupy the maximum number of length if number of data is less
than the maximum length.
4 Compare Char and Varchar datatypes?
Ans. CHAR VARCHAR
Fixed length datatype Variable length datatype
If a value is shorter than the length then blanks are If the values is shorter than the length then no blanks
added, but the size of value remains same. are added and values stored exactly of its length.
5 What is null value in MySQL database? Can you use nulls in arithmetic expressions?
Ans. If a column in a row has no value, then column is said to be null, or contain a null. Yes we can use null in arithmetic
expression but it should be avoid from use.
6 Which keyword eliminates the redundant data from a query result?
Ans. DISTINCT keyword
7 Which keyword retains duplicate output rows in a query result?
Ans. ALL keyword
8 How would you display system date as the result of a query?
Ans. SELECT CURDATE( );
9 How would you calculate 13 * 15 in SQL?
Ans. SELECT 13 * 15;
10 Which function is used to substitute NULL values in a query result?
Ans. IFNULL() function is used to substitute NULL value, for eg.
SELECT FnameIFNULL(Lname,”not mentioned”), birth from student;
This query will substitute all NULL rows of column Lname by string “not mentioned”.
11 Which operator concatenates two strings in a query result?
Ans. By using “ ” we can concatenate two string for eg.
SELECT “Fname Lname”;
12 Which comparison operator is used for comparing
(i) patterns (ii) character values (iii) null values (iv) ranges (v) list of values
Ans. (i) patterns – % , _
(ii) character values – LIKE, =
(iii) null values – IS NULL
(iv) ranges – <, <=, >, >=, BETWEEN
(v) list if values – IN , NOT IN

Type B: Short Answer Questions


Consider table Empl given in solved problem and answer the following questions

http://cbsecsnip.in
1 Write a query to display ename and sal of employees whose salary is greater than or equal to 2200 from table
empl?
Ans. SELECT ename, sal FROM empl WHERE sal >= 2200;
2 Write a query to display details of employees who are not getting commission from table empl?
Ans SELECT * FROM empl WHERE comm IS NULL;
3 Write a query to display employee name and salary of those employee who don’t have their salary in the range of
2500 to 4000?
Ans. SELECT ename, sal FROM empl WHERE sal NOT BETWEEN 2500 AND 4000;
OR
SELECT ename, sal FROM empl WHERE sal <2500 OR sal >4000;
4 Write a query to display the name, job title and salary of employees who do not have manager?
Ans. SELECT ename, job, sal FROM empl WHERE mgr IS NULL;
5 Write a query to display the name of employees whose name contains ‘A’ as third alphabet?
Ans. SELECT ename FROM empl WHERE ename LIKE '__A%';
6 Write a query to display the name of employees whose name contains ‘T’ as last alphabet?
Ans. SELECT ename FROM empl WHERE ename LIKE '%T';
7 Write a query to display the name of employees whose name contains ‘M’ as first alphabet ‘L’ as third alphabet?
Ans. SELECT ename FROM empl WHERE ename LIKE 'M_L%';
8 Write a query on the customers table whose output will exclude all customers with a rating <=100, unless they are
located in Shimla.
Ans. Table not given in book. Assuming that table have column rating and city query will be –
SELECT cust_name FROM customers WHERE rating >=100 OR city LIKE ‘Shimla’
9 Write a query that selects all orders (order table) except those with zeros or NULLs in the amt field.
Ans. Table not given in book. Assuming that table have column rating and city query will be –
SELECT * FROM order WHERE amt IS NOT NULL;
10 Write SQL commands for the following on the basis of given table SPORTS
TABLE- SPORTS
St_No Class Score Name Game1 Grade 1 SUPW Grade 2
10 7 8 Sammer Cricket B Photography A
11 8 3 Sujit Tennis A Gardening C
12 7 3 Kamal Swimming B Photography B
13 7 7 Venna Tennis C Cooking A
14 9 8 Archana Basketball A Literature A
15 10 3 Arpitt Cricket A Gardening C
(i) Display the names of the students who are getting a grade ‘C’ in either GAME or SUPW.
(ii) Display the different games offered in the school.
(iii) Display the SUPW taken up by the students, whose name start with ‘A’.
Ans. (i) SELECT name FROM sports WHERE grade1='C' OR grade2='C';
(ii) SELECT DISTINCT game1 FROM sports;
(iii) SELECT SUPW FROM `sports` WHERE name LIKE 'A%';
11 Write SQL commands for the following on the basis of given table SPORTS
TABLE- SPORTS
St No Class Score Name Game1 Grade 1 Game2 Grade 2
10 7 8 Sammer Cricket B Swimming A
11 8 3 Sujit Tennis A Skating C
12 7 3 Kamal Swimming B Football B
13 7 7 Venna Tennis C Tennis A
14 9 8 Archana Basketball A Cricket A
15 10 3 Arpitt Cricket A Athletics C
(i) Display names of the students who have grade ‘C’ in either Game1 or Game2 or both.
2

http://cbsecsnip.in
(ii) Display names of the students who have same game for both Game1 and Game2.
(iii) Display the games taken up by the students whose name starts with ‘A’.
Ans. (i) SELECT name FROM sports WHERE grade1='C' OR grade2='C';
(ii) SELECT name FROM sports WHERE game1 = game2;
(iii) SELECT gmes1,game2 FROM sports WHERE name LIKE 'A%';
12 Write SQL commands for the following on the basis of given table CLUB:
Table: CLUB
COACH_ID COACH_NAME AGE SPORTS DATOFAPP PAY SEX
1. KUKREJA 35 KARATE 27/03/1996 1000 M
2. RAVINA 34 KARATE 20/01/1998 1200 F
3. KARAN 34 SQUASH 19/02/1998 2000 M
4. TARUN 33 BASKETBALL 01/01/1998 1500 M
5. ZUBIN 36 SWIMMING 12/01/1998 750 M
6. KETAKI 36 SWIMMING 24/02/1998 800 F
7. ANKITA 39 SQUASH 20/02/1998 2200 F
8. ZAREEN 37 KARATE 22/02/1998 1100 F
9. KUSH 41 SWIMMING 13/01/1998 900 M
10. SHAILYA 37 BASKETBALL 19/02/1998 1700 M
(a) To show all information about the swimming coaches in the club.
(b) To list names of all coaches with their DATOFAPP (date of appointment) in descending order.
(c) To display a report, showing coachname, pay, age and bonus (15% of pay) for all the coaches.
Ans. (a) SELECT * FROM club WHERE sports LIKE 'SWIMMING'
(b) SELECT coach_name FROM club ORDER BY dateofapp DESC;
(c) SELECT coach_name, pay, age, pay *15 /100 AS "bonus" FROM club;
13 Write SQL commands for the following on the basis of given table STUDENT1:
Table: STUDENT1
S.NO. NAME STIPEND STREAM AVGMARK GRADE CLASS
1 KARAN 400.00 Medical 78.5 B 12B
2 DIVAKAR 450.00 Commerce 89.2 A 11C
3 DIVYA 300.00 Commerce 68.6 C 12C
4 ARUN 350.00 Humanities 73.1 B 12C
5 SABINA 500.00 Nonmedical 90.6 A 11A
6 JOHN 400.00 Medical 75.4 B 12B
7 ROBERT 250.00 Humanities 64.4 C 11A
8 RUBINA 450.00 Nonmedical 88.5 A 12A
9 VIKAS 500.00 Nonmedical 92.0 A 12A
10 MOHAN 300.00 Commerce 67.5 C 12C
(a) Select all the nonmedical students from Student1.
(b) List the names of those students who are in class 12 sorted by stipend.
(c) List all students sorted by Avgmark in descending order.
(d) Display a report, listing Name, stipend, stream and amount of stipend received in a year as summing that that
stipend is paid every month.
Ans. Student try this yourself, refer the queries given in question 12
14 Same as 12 and 13 only table is different.
15 Same as 12 and 13 only table is different.
16 Write SQL for the following on the basis of given table GRADUATE
TABLE : GRADUATE
S.NO. NAME STIPEND SUBJECT AVERGE RANK
1 KARAN 400 PHYSICS 68 1
2 DIVAKAR 450 COMPUTER SC 68 1

http://cbsecsnip.in
3 DIVYA 300 CHEMISTRY 62 2
4 ARUN 350 PHYSICS 63 1
5 SABINA 500 MATHEMATICS 70 1
6 JOHN 400 CHEMISTRY 55 2
7 ROBERT 250 PHYSICS 64 1
8 RUBINA 450 MATHEMATICS 68 1
9 VIKAS 500 COMPUTER SC 62 1
10 MOHAN 300 MATHEMATICS 57 2
(a) List the names of those students who have obtained rank 1 sorted by NAME.
(b) Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in year assuming that the
STIPEND is paid every month.
Ans. (a) SELECT name FROM graduate WHERE rank=1 ORDER BY name;
(b) SELECT name, stipend, subject, stipend*12 AS “Amount of Stipend” FROM graduate;
17 Write SQL commands for the following on the basis of given table relation teacher.
TABLE: Teacher
No. Name Age Department Dateofjoin Salary Sex
1 Jugal 34 Computer 10/01/97 12000 M
2 Sharmila 31 History 24/03/98 20000 F
3 Sandeep 32 Maths 12/12/96 30000 M
4 Sangeeta 35 History 01/07/99 40000 F
5 Rakesh 42 Maths 05/09/97 25000 M
6 Shyam 50 History 27/06/98 30000 M
7 Shiv Om 44 Computer 25/02/97 21000 M
8 Shalakha 33 Maths 31/07/97 20000 f
(a) To show all information about the teacher of history department
(b) To list the names of female teachers who are in Hindi department
(c) To list names of all teachers with their date of joining in ascending order.
Ans. (a) SELECT * FROM teacher WHERE department LIKE “History”;
(b) SELECT name FROM teacher WHERE sex =’F’ AND department LIKE ‘Hindi’;
(a) SELECT name, dateofjoin FROM teacher ORDER BY dateofjoin;

http://cbsecsnip.in

You might also like