SQL Puzzle: Putting Hyderabad First

How can we ensure that, based on the provided dataset below, 'Hyderabad' always appears in the first row of the 'StateCapital' column, with the remaining column values sorted in ascending order.

Input Data:


Expected Output:



Data Script:



CREATE TABLE StateDetails
(
	State NVARCHAR(150) ,
	StateCapital NVARCHAR(150)
)

INSERT INTO StateDetails
VALUES
	('TamilNadu','Chennai'),
	('AndhraPradesh', 'Amaravathi'),
	('Telangana','Hyderabad'),
	('Karnataka','Bengaluru'),
	('MahaRastra','Mumbai')

SELECT  * FROM StateDetails



Please try to answer the question, if you still not able to get it click below show button to see the answer.

No comments:

Post a Comment