Skip to main content

Posts

Showing posts with the label sql server

Rank and Dense_Rank Function in SQL Server

  In this article, I am going to discuss  Rank and Dense_Rank Function in SQL Server  with Examples.  RANK and DENSE_RANK Function in SQL Server: Both the RANK and DENSE_RANK functions were introduced in SQL Server 2005. Again both these functions are used to return sequential numbers starting from 1 based on the ordering of rows imposed by the ORDER BY clause. Let us first understand these functions in detail with some examples and then we will try to understand the difference between them. Note:  When you have two records with the same data, then it will give the same rank to both the rows. RANK Function in SQL Server: The following is the syntax to use the RANK function in SQL Server. As you can see, like the Row_Number function, here also the Partition By clause is optional while the Order By Clause is mandatory. The PARTITION BY clause is basically used to partition the result set into multiple groups. As it is optional, and if you did not specify the PARTI...

Joins In SQL Server

  SQL Joins (Inner, Left, Right and Full Join) SQL Join  operation combines data or rows from two or more tables based on a common field between them. In this article, we will learn about  Joins in SQL,  covering JOIN types, syntax, and examples. SQL JOIN SQL JOIN clause is used to query and access data from multiple tables by establishing logical relationships between them. It can access data from multiple tables simultaneously using common key values shared across different tables.  We can use SQL JOIN with multiple tables. It can also be paired with other clauses, the most popular use will be using JOIN with  WHERE clause   to filter data retrieval. SQL JOIN Example Consider the two tables below as follows:  Student: StudentCourse  : Both these tables are connected by one common key (column) i.e  ROLL_NO . We can perform a JOIN operation using the given SQL query: SELECT s.roll_no, s.name, s.address, s.phone, s.age, sc.course_id FROM ...