You are viewing a single comment's thread. Return to all comments →
-- Oracle solution --
SELECT * FROM
(SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY), CITY)
WHERE ROWNUM = 1
SELECT * FROM
(SELECT CITY, LENGTH(CITY) FROM STATION ORDER BY LENGTH(CITY) DESC, CITY)
WHERE ROWNUM = 1;
SIR CAN YOU EXPLAIN THIS PLEASE
SET @V1 := (SELECT MIN(LENGTH(CITY)) FROM STATION);
SET @V2 := (SELECT CITY FROM STATION WHERE LENGTH(CITY) = @V1 ORDER BY CITY LIMIT 1);
SET @V3 := (SELECT MAX(LENGTH(CITY)) FROM STATION);
SET @V4 := (SELECT CITY FROM STATION WHERE LENGTH(CITY) = @V3 ORDER BY CITY LIMIT 1);
PLease explain this
Thanks dhananjay.. it worked :-)
I second it. Can you please explain this.
This query is about unifying the results of two subqueries, so we use the UNION clause.
The WHERE ROWNUM = 1 in both subqueries is there in order to do a "TOP 1". That is the way this is done in Oracle. It is not very didactic but that's how Oracle undestands it. A simple explanation for that is here: https://stackoverflow.com/questions/3451534/how-do-i-do-top-1-in-oracle
The reason of what I have put in the ORDER BY, I think it is due to the statement of the challenge, but I'd have to look into it again.
All the best!
thanks sir it helps
may you please explain this to me to on how to understand it.
Thank you! None of the previous codes worked and I really has trying to do this for 3 days already, while for my codes there was always the "SQL query not ended properly" error.