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 |
|
pearlkin
Starting Member
3 Posts |
Posted - 2011-05-30 : 08:02:18
|
| Using alias name is a good approach??16 minutes agoHiWhich is the best approach and Tell Why??when we try to get data from more than 1 table by using joins. In Query we will prefix like a.ColumnName or tableName.ColumnNamefor eg1)Select a.id, a.name, a.address, b.salary,b.role from details as a inner join empdetails as b on a.id=b.idor2)Select details.id, details.name, details.address,empdetails.salary,empdetails.role from details inner join empdetails on details.id=empdetails.id |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2011-05-30 : 08:20:47
|
There's two general schools of thought1) Alias everything and be verbose (me) - It makes it easier for the next guy to understand what you are doing.2) Alias nothing except what you need to. (I don't like this but I do understand that some people use this because it makes it harder to get at 'accidentally correct query').I'd rewrite your query as:SELECT d.[Id] AS [DetailsId] , d.[Name] AS [DetailsName] , d.[Address] AS [DetailsAddress] , ed.[salary] AS [EmployeeSalary] , ed.[role] AS [EmployeeRole]FROM details AS d JOIN empdetails AS ed ON ed.[Id] = d.[Id] Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTIONEDIT - I'm *extremely* verbose but that's just me. I have a bit of a problem and like my SQL to be 'nice' |
 |
|
|
|
|
|
|
|