Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
kareem100
Starting Member
10 Posts |
Posted - 2011-07-14 : 17:54:14
|
| Hi,In answer to an earlier question, I was given some sql code. The code wasSELECT TOP(4) ProductName AS FourMostExpensiveProducts,UnitPriceFROM dbo.ProductsORDER BY UnitPrice DESCThe code worked fine but i have a question. After the select statement/keyword you have " AS FourMostExpensiveProducts ". What is this used for. My understanding of the select statement is that you have a series of column namess that are displayed when you run the query.As you can see my understanding of sql is very basic. Could someone direct me to a website which would enable me to learn more about sql.I should perhaps also mention that i'm using sql 2005 express.Regards,Kareem |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-07-14 : 17:58:48
|
| AS is a keyword indicating a column (or table) alias, in this case, FourMostExpensiveProducts. AS is optional, you could also write:SELECT TOP(4) ProductName FourMostExpensiveProducts,UnitPriceFROM dbo.ProductsORDER BY UnitPrice DESCIt's up to you which form you prefer. You can find more information on aliases here: http://msdn.microsoft.com/en-us/library/ms176104.aspx |
 |
|
|
kareem100
Starting Member
10 Posts |
Posted - 2011-07-15 : 17:28:09
|
| Hi,Yes, I do understand what you mean.By the way there are many different versions of SQL, I wanted to know which version are we using here.Are we using microsft sql ?Regards,Kareem |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-07-15 : 17:52:25
|
| Yes, SQLTeam specializes in Microsoft SQL Server. However, aliases are part of the ANSI SQL standard and should work the same way in most products. From memory I think Oracle was the only one that didn't recognize AS as a keyword. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-07-19 : 05:28:54
|
quote: Originally posted by robvolk Yes, SQLTeam specializes in Microsoft SQL Server. However, aliases are part of the ANSI SQL standard and should work the same way in most products. From memory I think Oracle was the only one that didn't recognize AS as a keyword.
It will recognize it for columns and not for tablesMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|