Examveda

If attribute "fruit" stores data as "apple, mango, banana" in table person then what will be the output of the following SQL command?
SELECT fruit FROM person
WHERE person_id=1
ORDER BY fruit;

A. apple, mango, banana

B. apple, banana, mango

C. mango, apple, banana

D. none of the mentioned

Answer: Option A

Solution (By Examveda Team)

This question asks you about how MySQL handles data in a table and how sorting works. Here's the breakdown:

1. The Table and Data
Imagine a table called "person" that stores information about people. One column in this table is called "fruit".
The "fruit" column for a person with "person_id" equal to 1 contains the following data: "apple, mango, banana".

2. The SQL Query
The SQL query you see is designed to fetch the data in the "fruit" column. Let's break it down:
* SELECT fruit FROM person: This part tells the database to get the values from the "fruit" column in the "person" table.
* WHERE person_id=1: This part specifies that we only want the data for the person with "person_id" equal to 1.
* ORDER BY fruit: This part tells MySQL to arrange the result alphabetically based on the "fruit" values.

3. Understanding the Output
Since "fruit" is stored as "apple, mango, banana", the "ORDER BY fruit" clause will sort these values alphabetically. Therefore, the output will be:
apple, banana, mango

The Correct Answer:
Option B: apple, banana, mango is the correct answer.

This Question Belongs to MySQL >> MySQL Miscellaneous

Join The Discussion

Related Questions on MySQL Miscellaneous