As SQL

Galaxy Glossary

What does the AS keyword do in SQL?

The AS keyword in SQL is used to rename columns or tables during a query. This is a fundamental tool for organizing and presenting data in a more readable and manageable format. It's crucial for clarity and flexibility in data manipulation.
Sign up for the latest in SQL knowledge from the Galaxy Team!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Description

The `AS` keyword in SQL is a powerful tool for modifying the way data is presented in query results. It allows you to rename columns or tables to make your output more meaningful and easier to understand. This is particularly useful when dealing with multiple tables or when you need to tailor the output to specific reporting needs. For example, if you're joining two tables and one table has a column named 'CustomerID' and the other has a column named 'Client_ID', using `AS` lets you rename one of these columns to a more consistent name, like 'Customer ID'. This improves readability and avoids ambiguity. Renaming tables with `AS` is also helpful when you need to refer to a table by a different name within a complex query. This can be crucial for subqueries or when you need to join multiple tables with similar column names without conflicts. It's a simple yet essential technique for data manipulation and presentation.

Why As SQL is important

The `AS` keyword is crucial for creating clear and maintainable SQL queries. It enhances readability, especially in complex queries involving multiple tables. This makes your code easier to understand and modify, which is essential for collaboration and long-term project success.

Example Usage


-- Example of renaming a column
SELECT
    CustomerID AS CustomerID,
    FirstName,
    LastName
FROM
    Customers;

-- Example of renaming a table
SELECT
    c.CustomerID,
    c.FirstName,
    o.OrderID
FROM
    Customers AS c
JOIN
    Orders AS o ON c.CustomerID = o.CustomerID;

Common Mistakes

Want to learn about other SQL terms?