SQLforGeeks
  • Home
  • SQL
  • SQL Tutorial
  • SQL Syntax
  • Our Services
Contact
  1. SQL
  2. SQL Aliases

Text copied!

« Previous
Next »

SQL Aliases

June 30, 2023, 8:03 p.m. under SQL

  • Hi! You should check SQL Subquery post first.

    In SQL, 'Alias' is used to assign an alternate name to a table or column in a query. It uses "AS" keyword to assign an alternate name.

    Here's the ideal syntax :
    SELECT column1 AS alias_name, column2 AS alias_name, ...
    FROM table_name AS alias_name;
    Here's an example of Alias :

    Let's suppose we have two tables :

    [a] Employees Table :

    → It contains columns [Employee_Id], [Employee_Name], [Gender] and [Department_Id].

    [b] Departments Table :

    → It contains columns [Department_Id] and [Department_Name].

    SQL Aliases

    1. Let's assume you want to retrieve the "Employee_Name" column as "Name" only and their respective department names by joining the [Employees] and [Departments] tables together based on matching values in both the tables.

    2. Please run the following SQL statement :

    SELECT Emp.Employee_Name AS [NAME], Emp.Department_Id, Dpt.Department_Name
    FROM [Employees] AS Emp
    INNER JOIN [Departments] AS Dpt
    ON Emp.Department_Id = Dpt.Department_Id;
            

    3. Above statement selects the columns from both tables based on the matching values in the 'Department_Id' column and returns the resulting data as the output.

    SQL Aliases

    In this example, [Employees] and [Departments] tables are aliases for 'Emp' and 'Dpt' respectively.

    [Name] is a alias assigned to 'Employee_Name' column. This can be useful when you want to assign alternative names to columns in the result set.

    Frequently Asked Questions :

    What is an alias in SQL?

    An alias in SQL is a temporary name assigned to a table or column.

    What are the benefits of alias in SQL?

    The benefits of aliases in SQL include improved readability, shorter query syntax, and avoidance of naming conflicts.

    How to use two alias in SQL?

    To use two aliases in SQL, you can assign aliases to multiple tables in a query by separating them with commas and providing each with a unique alias.

    How do you write an alias name example?

    An example of writing an alias name in SQL:
    
    SELECT emp.name AS employee_name, dept.name AS department_name
    FROM employees AS emp, departments AS dept
    WHERE emp.department_id = dept.department_id;
    Thank You! You should check Temp table post next.
    « Previous
    Next »
    RELATED :

    What is SQL

    What is T-SQL

    Difference between DBMS and Data Warehouse

    Download SQL Server

    Install SQL Server

    Download SQL Server Management Studio SSMS

    SQL Server Management Studio

    SQL Database

    Download database

    Restore database

    Backup database

    Attach database

    Detach database

    Create database

    Delete database

    Rename database

    Select database

    Database offline

    Database online

    SQL Commands

    SQL Tables

    Create table

    Truncate table

    Delete table

    Rename table

    Select table

    Alter table

    SQL Data Types

    SQL Comments

    SQL Constraints

    SQL Joins

    SQL inner join

    SQL left join

    SQL right join

    SQL full join

    SQL cross join

    SQL self join

    INSERT INTO SELECT statement

    INSERT INTO statement

    SQL Clauses

    SELECT clause

    FROM clause

    WHERE clause

    GROUP BY clause

    HAVING clause

    ORDER BY clause

    JOIN clause

    UNION clause

    UNION ALL clause

    TOP clause

    DISTINCT clause

    SQL Operators

    SQL Arithmetic operators

    SQL Comparison operators

    SQL Logical operators

    UNION operator

    UNION ALL operator

    INTERSECT operator

    EXCEPT operator

    LIKE operator

    NOT LIKE operator

    IN operator

    NOT IN operator

    IS NULL operator

    IS NOT NULL operator

    EXISTS operator

    NOT EXISTS operator

    BETWEEN operator

    NOT BETWEEN operator

    SQL Functions

    SQL Built-In functions

    CHARINDEX function

    DATEADD function

    CONCAT function

    LEN function

    REPLACE function

    SUBSTRING function

    CASE statement

    GETDATE function

    DATEPART function

    DATEDIFF function

    CAST function

    TRY_CAST function

    CONVERT function

    TRY_CONVERT function

    ISNULL function

    NULLIF function

    COALESCE function

    SQL Window functions

    ROW_NUMBER function

    RANK function

    DENSE_RANK function

    IIF function

    CHOOSE function

    SQL Store Procedure

    Store Procedure vs. Function

    SQL Subquery

    Temp table

    SQL Error Handling

    SQL Variables

    SQL Views

    SQL Merge

    SQL CTE

    SQL WITH TIES

    Define Transaction in DBMS

    ACID properties in DBMS

    Types of Triggers in DBMS


    • Have Some Questions?
    logo

    Elevate your data experience with SQL excellence

    Quick Links
    •  Home
    •  SQL Tutorial
    •  SQL Syntax
    •  Our Services
    Our Services
    • Web Development
    • BI Development
    • Data Warehousing
    • Data Integration ETL


    Follow Us

    GST Registered: XXAXXXXXXXZX
    Mumbai, Maharashtra, India support@sqlforgeeks.com

    © 2025 Copyright™ | All Rights Reserved | Privacy Policy