Search code examples
sqlgrailsgroovy

Why is character "A" used in select instead of "*"?


In a groovy application the query contains just a letter in the select.

Example: SELECT a FROM Employee a WHERE a.emplID =123456

My question is that the same as: SELECT * FROM Employee WHERE emplId=123456

If not what is the above query doing?


Solution

  • a in this case is an alias to the Employee table.

    An alias is declared in the FROM statement, then referenced in the SELECT statement.

    SELECT a
    FROM Employee a
    

    This is basically the same as:

    SELECT *
    FROM Employee
    

    If you want to reference specific columns when using an alias, it would be done like this:

    SELECT a.ID, a.Name, a.Salary
    FROM Employee a
    

    Hope this helps