Self Studies

Databases Test 4

Result Self Studies

Databases Test 4
  • Score

    -

    out of -
  • Rank

    -

    out of -
TIME Taken - -
Self Studies

SHARING IS CARING

If our Website helped you a little, then kindly spread our voice using Social Networks. Spread our word to your readers, friends, teachers, students & all those close ones who deserve to know what you know now.

Self Studies Self Studies
Weekly Quiz Competition
  • Question 1
    1 / -0

    In which case would you use a FULL OUTER JOIN?

    Solution
    • The FULL OUTER JOIN (FULL JOIN) keyword returns all records when there is a match in either left (table1) or right table records and the record with unmatched data from BOTH tables
    • The LEFT OUTER JOIN (LEFT JOIN) keyword returns all records when there is a match in either left (table1) or right table records and the record with unmatched data from LEFT tables
    • The RIGHT OUTER JOIN (RIGHT JOIN) keyword returns all records when there is a match in either left (table1) or right table records and the record with unmatched data from RIGHT tables
  • Question 2
    1 / -0

    The number of rows returned by SQL query on the given EMP table is ________

    SELECT *

    FROM EMP

    WHERE eno NOT IN (

    SELECT manager FROM EMP);

    eno

    ename

    manager

    1

    a

    2

    2

    b

    3

    3

    c

    4

    4

    d

    NULL

    Solution

    NOT IN returns 0 records when compared against an unknown value.

    The inner query return {2, 3, 4, NULL}. When outer query checks whether each eno is not in {2, 3, 4, NULL}, the where condition will return true. Hence one row will be selected.

  • Question 3
    1 / -0

    Given two tables EMPLOYEE (EID, ENAME, DEPTNO)

                DEPARTMENT (DEPTNO. DEPTNAME)

    Find the most appropriate statement of the given query:

                  Select count (*) total

                  from EMPLOYEE where DEPTNO IN (D1, D2)

                  group by DEPTNO

                  having count (*) >5 

    Solution

    Given query is:

                 Select count (*) total

                 from EMPLOYEE where DEPTNO IN (D1, D2)

                 group by DEPTNO

    having count (*) >5

    STEP 1: It will first find the all the entries with department no. as D1 and D2 with the help of natural join from both the relations.

    STEP 2: Then in the resulting table, it groups the tuples with the department no. (DEPTNO)

    STEP3: Then select all those tuples having count > 5.

    STEP 4: Finally, it results in the total number of employees of department D1 and D2 if their total is > 5.

  • Question 4
    1 / -0

    Consider a relation EdTech(Year, Famous, Popular) columns contain turnover in crores of Famous and Popular organization. If a cell contains null means turnover was not calculated for that particular year.

    EdTech

    Year

    Famous

    Popular

    1998

    10

    19

    1999

    15

    null

    2000

    null

    15

    2001

    21

    null

    2002

    16

    17

    2003

    23

    22

    2004

    13

    null

    2005null12
    20061918
    2007null16

     

    SQL query on the above relation is SELECT AVG(Popular)  FROM EdTech.

    What is the output of the given SQL query (answer upto 1 decimal place)?

    Solution

    Since increment containing null value is ignored

    Average = \(\frac{{19 + 15 +17 + 22 + 12 + 18 + 16\;}}{7} = 119\)

    Average = 17

    Important Points:

    Tuples with null value is ignored and hence it is not included in the final calculation.
  • Question 5
    1 / -0

    Given relations R(w, x) and S(y, z), the result of SELECT DISTINCT w, x from R, S is guaranteed to be same as R, provided.

    Solution

    Concept:

    • SQL Relations are MULTISET, not SET. So, R or S can have duplicated.
    • If S is empty, then R × S = empty and hence it will not equal to R
    • If R has duplicates, in that case, due to distinct keyword those duplicates will be eliminated in the final result and SQL query will not be equal to R. So, R cannot have duplicates.

     

    Option 1: R has no duplicates and S is non-empty

    This is true:

    Option 2: R and S have no duplicates

    Since S can be empty ∴ R × S = 0 it is false

    Option 3: S has no duplicates and R is non-empty

    Since R can be duplicate it is false

    Option 4: R and S has same number of tuples

    Since R can be duplicate it is false

    Example:

    R(x, y)

    w

    x

    1

    2

    1

    2

     

    S(y, z)

    y

    z

    3

    4

    5

    2

     

    R × S:

    w

    x

    y

    z

    1

    2

    3

    4

    1

    2

    5

    2

    1

    2

    3

    4

    1

    2

    5

    2

     

    SELECT DISTINCT w, x from R, S

    Output:

    w

    x

    1

    2

     

    This proves option 3 and 4 an incorrect statement

  • Question 6
    1 / -0
    Consider a Student table, it has two attributes which are the student_name and student seat_no. The student seat number is not null and also it is unique.  

    The SQL statement is

    Select count(*) from Student

    where seat_no  ≤  All (Select seat_no from Student);

    What is the output of the above statement?

    Solution

    Concept:

    null + unique = Primary key, Hence seat_no column is the primary key.

    count(*)  is the aggregation function that is used to count the total no of rows in the table.

    Explanation: (taking the small example)

    Student table:

    student_name

    seat_no

    A

    2

    B

    7

    C

    9


    Inner query result: Select seat_no from Student

    Output:

    seat_no

    2

    7

    9


    Outer query result:

    Select count(*) from Student

    where seat_no  ≤ All (2, 7, 9);

    The only condition true is 2 ≤ All(2, 7, 9)

    Therefore count is 1.

  • Question 7
    1 / -0

    A relational database contains two tables Traveler and Visited as shown below:

    Traveler

    ID

    Name

    E01

    Arya

    E02

    Shruti

    E03

    Zahida

    E04

    Madhu

    E05

    Hiteshri

    E06

    Archana

    E07

    Shradha

     

    Visited

    ID

    Month

    City

    Amount

    E02

    November

    Gangapur

    10K

    E01

    October

    Mumbai

    30K

    E02

    March

    Basti

    10K

    E01

    January

    Godda

    20K

    E06

    April

    Gorakhpur

    15K

    The primary key of the Traveler table is ID. For the Visited table, the columns

    ID and City together form the primary key. Consider the SQL query given

    below:

    SELECT T.Name, sum(V.Amount)

    FROM Traveler T, Visited V

    WHERE T.ID = V.ID OR V.Amount = 30 K

    GROUP BY T.Name;

    The number of rows returned by the above SQL query is ________.
    Solution

    Let X ≡ T × V where T.ID = V.ID OR V.Amount = 30K

    ID

    Name

    V.ID

    V.Month

    V.city

    V.Amount

    E01

    Arya

    E01

    October

    Mumbai

    30K

    E01

    Arya

    E01

    January

    Godda

    20K

    E02

    Shruti

    E01

    October

    Mumbai

    30K

    E03

    Zahida

    E01

    October

    Mumbai

    30K

    E04

    Madhu

    E01

    October

    Mumbai

    30K

    E05

    Hiteshri

    E01

    October

    Mumbai

    30K

    E06

    Archana

    E01

    October

    Mumbai

    30K

    E07

    Shradha

    E01

    October

    Mumbai

    30K

     

    Modified Query:

    SELECT T.Name, sum(P.Marks)

    FROM X GROUP BY S.Student_name;

    Final output:

    Name

    V.Amount

    Arya

    50K

    Shruti

    30K

    Zahida

    30K

    Madhu

    30K

    Hiteshri

    30K

    Archana

    30K

    Shradha

    30K

     

    The number of rows returned by the above SQL query is 7.

  • Question 8
    1 / -0

    Consider the following relational schema:

    employee(empId,empName,empDept)

    customer(custId,custName,salesRepId,rating)

    salesRepId is a foreign key referring to empId of the employee relation. Assume that each

    employee makes a sale to at least one customer. What does the following query return?

    SELECT empName FROM employee E

    WHERE NOT EXISTS (SELECT custId FROM customer C WHERE C.salesRepId = E.empId

    AND C.rating <> ’GOOD’);

    Solution

    Concept:

    • NOT EXISTS operator returns true if the underlying sub query return no record.
    • If single record is matched by the inner sub query, the NOT EXISTS operator will return false, and the sub query execution can be stopped.


    Explanation:

    Example:

    Employee table:

    empID

    empName

    EmpDept

    E1

    Raju

    D1

    E2

    Ashok

    D2

    E3

    Madhu

    D1

     

    Customer table:

    custID

    custName

    salesRepID

    Rating

    C1

    Dilip

    E1

    GOOD

    C2

    Pooja

    E1

    BAD

    C3

    Kirti

    E2

    BAD

    C4

    Kshitij

    E3

    GOOD

     

    • Employee table entry E1 will matched with customer C1 in customer table but rating is GOOD so inner query will not return a record and NOT EXISTS will return true now employee entry e1 will matched with customer C2 but rating is bad so NOT EXISTS will return false and the sub query execution can be stopped and E1 will not print.
    • Employee entry E2 will matched with customer C3 but Rating is BAD so NOT EXISTS will return false and E2 will not print.
    • Employee entry E3 will matched with customer C4 but Rating is GOOD so NOT EXISTS will return true and E3 will print.
    • This is nothing but name of all the employees with all their customers having a GOOD rating.
  • Question 9
    1 / -0

    Consider a database with the relation schema STUDENT(StId, StName, and CourseName). An instance of the schema STUDENT is given below 

    STUDENT

    StId

    StName

    CourseName

    1

    XYA

    AAA

    2

    XYB

    AAA

    3

    XYC

    AAA

    4

    XYD

    ABB

    5

    XYE

    ABB

    6

    XYF

    ABB

    7

    XYG

    ABB

    8

    XYH

    ACC

    9

    XYI

    ACC

    10

    SYJ

    ADD

    11

    XYK

    ADD

    12

    XYL

    ADD

    13

    XYM

    AEE

    14XYNAEE

    SQL query on the above instance is are given below.

    SELECT AVG(S.cnt

    FROM S

    WHERE(CourseName, cnt) IN

              (SELECTED CourseName, COUNT(StId) AS

                                                        CourseName, cnt)

               FROM STUDENT

               GROUP BY CourseName)

     

    The output of executing the SQL query is _________.

    Solution

    Concept:

    Count the number of StIDs corresponding to a particular department and then write as attribute value of cnt in new relational schema S.

    Explanation:

    SQL query results                            

    S

    CourseName

    cnt

    AAA

    3

    ABB

    4

    ACC

    2

    ADD

    3

    AEE

    2

     

    AVG(S. cnt) will find out the average of Num values in the returned query.,

    \(Average = \;\frac{{3 + 4 + 2 + 3 + 2}}{5} = 2.8\)

  • Question 10
    1 / -0

    Database table name Tuition_Records is given below

    Students

    Teachers

    Fees

    Aniket

    Uday

    10000

    Barbie

    Rishi

    7000

    Chandresh

    Uday

    12000

    Dharma

    Rishi

    9000

     

    SELECT count(*) FROM ((SELECT students, Teachers FROM Tuition_Records) AS A NATURAL JOIN (SELECT Teachers, Fees FROM Tuition_Records))

    What is the output of the following SQL query?
    Solution

    A:

    Students

    Teachers

    Aniket

    Uday

    Barbie

    Rishi

    Chandresh

    Uday

    Dharma

    Rishi

     

    B:

    Teachers

    Fees

    Uday

    10000

    Rishi

    7000

    Uday

    12000

    Rishi

    9000

     

    A NATURAL JOIN B

    Students

    Teachers

    Fees

    Aniket

    Uday

    10000

    Aniket

    Uday

    12000

    Barbie

    Rishi

    7000

    Barbie

    Rishi

    9000

    Chandresh

    Uday

    10000

    Chandresh

    Uday

    12000

    Dharma

    Rishi

    7000

    Dharma

    Rishi

    9000

     

    SELECT count(*) FROM A NATURAL JOIN B

    OUTPUT: 8
Self Studies
User
Question Analysis
  • Correct -

  • Wrong -

  • Skipped -

My Perfomance
  • Score

    -

    out of -
  • Rank

    -

    out of -
Re-Attempt Weekly Quiz Competition
Selfstudy
Selfstudy
Self Studies Get latest Exam Updates
& Study Material Alerts!
No, Thanks
Self Studies
Click on Allow to receive notifications
Allow Notification
Self Studies
Self Studies Self Studies
To enable notifications follow this 2 steps:
  • First Click on Secure Icon Self Studies
  • Second click on the toggle icon
Allow Notification
Get latest Exam Updates & FREE Study Material Alerts!
Self Studies ×
Open Now