Databases Reporting with SQL Working with Text Changing Cases of Strings

Maryam Naz
Maryam Naz
3,612 Points

how to combine "AS" statement so I wont have to re-type AS each time?

Hi all,

Solution 1 below does the job but isn't elegant. Anyway I can make Solution 2 work ( that is to only state "AS" once?

Solution 1: works, but I have to type "AS twice"

SELECT LOWER(title) AS lowercase_title, UPPER(author) AS uppercase_author FROM books;

Solution 2: how to combine all the "AS" together, to avoid retyping "AS", something example below?

SELECT LOWER(title) , UPPER(author) AS (lowercase_title, uppercase_author) FROM books;

1 Answer

Steven Parker
Steven Parker
203,226 Points

The first example is a correct solution. The second one is not proper SQL syntax, and aliases must be applied individually.

A common observation about SQL is that it tends to be a bit verbose and has very few "shortcut" variations in the syntax.

Maryam Naz
Maryam Naz
3,612 Points

Thanks Steven.

Steven Parker
Steven Parker
203,226 Points

Maryam Naz — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!