SQL WHERE

Summary: in this tutorial, you will learn how to use the SQL WHERE clause to filter rows based on one or more conditions. Introduction to SQL WHERE clause  To select specific rows from a table based on one or more conditions, you use the WHERE clause in the SELECT statement. Here’s the syntax of the WHERE clause: SELECT…

SQL FETCH

Summary: in this tutorial, you will learn how to use the SQL FETCH clause to limit the number of rows returned by a query. Introduction to SQL FETCH clause To limit the number of rows returned by a query, you use the LIMIT clause. The LIMIT clause is widely supported by many database systems such as…

What is SQL Server

SQL Server is a relational database management system (RDBMS) developed and marketed by Microsoft. Similar to other RDBMS software, SQL Server is built on top of SQL, a standard programming language for interacting with relational databases. SQL Server is tied to Transact-SQL, or T-SQL, Microsoft’s implementation of SQL, which includes a…
dense rank in SQL

DENSE_RANK SQL

Problem We can easily use the MAX() function in SQL Server to find the maximum value in a table. However, there are situations when the second-highest or third-highest record is needed from the table. SQL Server has no direct SQL functions to fetch the second or third highest from the table, so…
SQL rank function

RANK() Function in SQL

The RANK() function in SQL is a powerful window function in SQL Server used to assign a rank to each row within a result set. It is particularly useful when we need to assign a rank to a group of rows based on some sorting criteria and want to differentiate between rows…
SQL LEAD()

SQL LEAD()

The LEAD() window function takes a column and an integer offset as arguments and returns the value of the cell in that column that is the specified number of rows after the current row. A third argument can be added to fill cells that do not have a corresponding row. Syntax LEAD(column1_name,…
sql lag()

SQL LAG()

The LAG() window function facilitates access to previous rows based on the offset argument. It can be particularly useful when a comparison of a previous value is necessary without the use of a self join. There is a similarity to the LEAD() function with the difference being the accessible rows.LEAD() accesses subsequent rows while SQL LAG() accesses…
How to Use ROW_NUMBER OVER() in SQL

How to Use ROW_NUMBER OVER() in SQL

Sometimes you need to know the position of rows in a result set. Learn how using ROW_NUMBER and OVER can make it happen! Have you ever needed to add a sequential number to the records returned by an SQL query? Or perhaps you need to create a ‘top n’ report based…
sql subquery

SQL Subquery

Summary: In this tutorial, you’ll learn how to use SQL subqueries to form flexible queries for retrieving data from the database. Introduction to SQL subquery  A subquery is an SQL query nested inside another query. The query that contains a subquery is known as an outer query. To write a subquery,…
left join in sql

SQL LEFT JOIN

Summary: in this tutorial, you’ll learn how to use the SQL LEFT JOIN clause to merge rows from two tables. Introduction to SQL LEFT JOIN clause  The LEFT JOIN clause is an optional clause of the SELECT statement. The LEFT JOIN clause allows you to merge rows from two tables. Here’s the syntax of LEFT JOIN clause: SELECT column1, column2…