All Tips & Questions

Tip of the day

SQL Server: SQL aliases are used to temporarily rename a table or a column heading

SQL aliases are used to temporarily rename a table or a column heading in queries. Basically aliases are created to make column names more readable.

Aliases can be useful when:

  • There are more than one table involved in a query
  • Functions are used in the query
  • Column names are big or not very readable
  • Two or more columns are combined together
  • Same Table joining multiple times in one query(like self-join)

- by Venkateswarlu Cherukuru

Question of the day

SQL Server: What is the difference between RANK() and DENSE_RANK() functions?


This function does much the same thing as ROW_NUMBER(), only it acknowledges ties in the columns specified in the ORDER BY clause, and assigns them the same rank. Where a tie occurs, the numbers that would otherwise have been "used up" are skipped, and numbering resumes at the next available number. As you can see, RANK() leaves a gap whenever there is a tie.




This function doesn't like gaps and doesn't leave any rank if tie occures. DENSE_RANK() "fills in the gaps". It starts from the next number after a tie occurs, so instead of 1, 2, 3, 3, 5, 6 you get 1, 2, 3, 3, 4, 5 for example.


For more details click on Ranking Functions in SQL Server

- by Venkateswarlu Cherukuru

We are inviting Tips & Questions from you. Click Here to share your valuable Tips & Questions on this website.

  • Your Tips & Questions will be displayed on website, after validating the information you provided.
  • Tips & Questions will be refreshed on every day 12:00 AM IST.