Alex
Alex

Reputation: 750

what does this part of my sql SELECT statement mean?

SELECT  sh.id AS sh_identifier

my column name is id, what is the sh. bit before it called and how do i use this correctly? thanks.

Upvotes: 0

Views: 338

Answers (7)

Widor
Widor

Reputation: 13275

As this is only part of the full query, the bit that answers your question is missing.

the sh. will refer to a Table - or an alias of one - which appears in the FROM clause.

If you're only selecting from one table, it's not mandatory.

Upvotes: 1

Icarus
Icarus

Reputation: 63956

It's aliasing the sh.id field as sh_identifier. In this case, the person who wrote the query just tried to give a more meaningful name to the id column of the sh table.

Upvotes: 1

Blagovest Buyukliev
Blagovest Buyukliev

Reputation: 43508

sh specifies the name of the table where the corresponding field exists.

In statements where just one table is used it is not necessary, but it is required to avoid ambiguity when more than one table is used and any two tables have a field with the same name.

Upvotes: 1

JMax
JMax

Reputation: 26591

sh is the table name

sh.id is the column id from the table sh

See the documentation for more information

Upvotes: 1

ceejayoz
ceejayoz

Reputation: 180004

sh. is the name of the table, or an alias (SELECT * FROM a_long_table_name AS sh) of one.

Upvotes: 1

Tito
Tito

Reputation: 71

You usually use it to define the table names in more advanced queries.

SELECT  mytable.id AS sh_identifier FROM mytable

Upvotes: 2

Conrad Frix
Conrad Frix

Reputation: 52645

Its a table or view name or table alias or in some cases an inline view alias

Table Name

SELECT sh.id as sh_identifier
FROM sh

Table alias

SELECT sh.id as sh_identifier
FROM mytable sh

Inline view

SELECT sh.id as sh_identifier
FROM (SELECT * FROM mytable) sh

Upvotes: 7

Related Questions