what order are the rows returned?

In the office table, the city column is structured as shown:
Mysql> show columns from office like ‘city’\G
—————————————————1. row ———————__________________
Field: city
Type: enum(‘paris’.’Amsterdam’.’New York’.’Tokyo’)
Null: Yes
Key:
Default:NULL
Extra:
Consider the output of the SELECT query executed on the office table:
Mysql> SELECT DISTINCT city FROM office ORDER BY city:

If the query is written as:
SELECT DISTINCT city FROM office ORDER BY CAST(city AS CHAR)
In what order are the rows returned?

In the office table, the city column is structured as shown:
Mysql> show columns from office like ‘city’\G
—————————————————1. row ———————__________________
Field: city
Type: enum(‘paris’.’Amsterdam’.’New York’.’Tokyo’)
Null: Yes
Key:
Default:NULL
Extra:
Consider the output of the SELECT query executed on the office table:
Mysql> SELECT DISTINCT city FROM office ORDER BY city:

If the query is written as:
SELECT DISTINCT city FROM office ORDER BY CAST(city AS CHAR)
In what order are the rows returned?

A.
Paris, Amsterdam. New York, Tokyo

B.
Tokyo, New York, Amsterdam, Paris

C.
Amsterdam, New York, Paris, Tokyo

D.
Tokyo, Paris, New York, Amsterdam



Leave a Reply 6

Your email address will not be published. Required fields are marked *


leo

leo

A !!!!! Try…

Jay

Jay

I tried and got C.

create table office
(
city enum(‘Paris’,’Amsterdam’,’New York’,’Tokyo’) null
);

insert into office values (‘Paris’),(‘Amsterdam’),(‘New York’),(‘Tokyo’);

SELECT distinct city FROM office order by city;

SELECT DISTINCT city FROM office ORDER BY CAST(city AS CHAR);

city
‘Amsterdam’
‘New York’
‘Paris’
‘Tokyo’

jhutch

jhutch

It’s c as you’re casting it back to char and it then follows normal string rules if you didn’t cast it the char it would be A.