user163831
user163831

Reputation: 1211

What does the 'a' do in this MySQL query? It doesn't run without it

The 'a' at the end of this:

SELECT
email_home
FROM
(SELECT email_home FROM sales
UNION ALL
SELECT email_work FROM sales) a

What's it do/for? The code doesn't run without it. Thanks.

Upvotes: 0

Views: 42

Answers (3)

Domain
Domain

Reputation: 11808

As you are using subquery in From clause MySql requires alias name. In your case "a" is just a alias given to your subquery in From clause. for detail information read this

Upvotes: 0

durbnpoisn
durbnpoisn

Reputation: 4669

It sets the name of an alias to the table to "a".

Presumably, you could reference objects in that table by using "a.[columnName]" for future stuff.

Upvotes: 0

atxdba
atxdba

Reputation: 5216

It's just an alias. Mysql requires all sub queries like that require a specific name. People just use 'a' as convention if they aren't really going to use it.

You could specify the column name thusly:

a.email_home

Upvotes: 2

Related Questions