开发者

SQL syntax Newbie student

Describe the output of the following SQL query:

select custId, name
from customer
where region = "New York"
UNION 
select cust.custId, cust.name
from custo开发者_如何学运维mer cust
where cust.custId IN (select cust_order.custId
from customer_order cust_order, company_employee comp_emp
where cust_order.salesEmpId = comp_emp.empId
AND comp_emp.name = 'DANIEL');

My question is: at the line which contains from customer cust is 'cust' referring to a column in the customer table?

This is a homework question I have identified the components leading up to this line and I think that cust is a column in the customer table... I am not asking for an overall solution just a bit of encouragement if I am on the right track...


cust is an alias for the Customer table. So instead of writing customer.custId, you can write cust.custId


You should have a look at Sql Server TABLE ALIASING

Have a closer look at SELECT Clause (Transact-SQL) and search for alias


Cust is an alias on the customer table. It is used to enable you to not have to spell out the whole table name everywhere.


No - its creating an alias for the table

  • so there's less to type each time
  • and to deal with the scenario where you want to use multiple 'copies' of the table in the same query.


cust is an alias for customer to make it shorter to type and read.


'cust' is just an alias for the 'customer' table name. It allows you to write 'cust.name' rather than 'customer.name'


cust is an alias for the customer table.

Since the query is looking at one table as two separate tables (or at least result sets) for the purposes of the query, this allows the DB to know that when you say "Customers" as the table name, you mean the ones from New York, while "Cust" means ones where the sales employee name is Daniel.

Alias names are described here: http://www.w3schools.com/sql/sql_alias.asp


"cust" is used as an alias of the "customer" table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜