In
SELECT a.NAME, a.NUMBER, a.STRING, a.RDB$DB_KEY FROM ADMIN a
what does a stand for?
Thanks.
In
SELECT a.NAME, a.NUMBER, a.STRING, a.RDB$DB_KEY FROM ADMIN a
what does a stand for?
Thanks.
a is what is called a table alias. In the part of the query that says:
FROM ADMIN a
By placing "a" after the table name, you have created an alias that can now be used in place of the table name. Without the alias, you would need to use the table's full name in order to fully-qualify the column name(s) that you are referring to in the query.
Without the table alias, your query would look like this:
SELECT ADMIN.NAME, ADMIN.NUMBER, ADMIN.STRING, ADMIN.RDB$DB_KEY FROM ADMIN
Although since you are only selecting columns from a single table, the table name (or alias) actually isn't needed at all in this example.
A is an alias for the table.
You can change a to any valid identifier, it isn't dependant on the underlying schema. Usually it's used to differentiate fields from different tables, saves you typeing the full table name each time (makes the SQL easier to read with a short alias).
It isn't actually required in the sample you gave,
SELECT NAME, NUMBER, STRING, RDB$DB_KEY FROM AMDIN
should work just as well
The query is using a like that just so that you don't have to write ADMIN.NAME, ADMIN.NUMBER, etc etc. If you have fifteen fields on your table and your table has a name like VPCPDEEE it gets very tiresome to type the same table name over and over.
a = ADMIN
Equivalent:
SELECT ADMIN.NAME, ADMIN.NUMBER, ADMIN.STRING, ADMIN.RDB$DB_KEY FROM ADMIN
An alias for the table ADMIN. It's not necessary here, because you only have one table in your query.
When you have more than one table, and some of the columns are the same, then you need to distinguish between them. One way is to write the table name in front of the column name. E.g.,
Select ADMIN.Name, person.name from ADMIN, person where person.id = admin.id
To make this shorter, add aliases for the table names.
select a.Name, p.Name from ADMIN a, person p where person.id = admin.id
The a is used as an alias for the ADMIN table.
When it is correct to use an alias, and of what form that alias should take can raise some strong opinions from writers of sql.
Heres a couple of stackoverflow questions on the subject.
http://stackoverflow.com/questions/198196/when-to-use-sql-table-alias
http://stackoverflow.com/questions/11043/sql-table-aliases-good-or-bad
In the ISO/ANSI SQL-92 Standard this is called a 'table correlation name', though the colloquial 'alias' seems to be more commonly used.