How to get previous row value in sql ?

The most common method to fetch previous row value in SQL is by using the LAG function. The LAG function returns the previous row value. Depending on the order by clause the previous row is determined and the column value is returned. catid previous_catid 1 NULL 2 1 3 2 4 3 5 4 6 … Read more

Redshift Select Distinct

Redshift SELECT Distinct is used to fetch unique rows from the table. DISTINCT is applied to all the columns mentioned in the SELECT clause and not just the first column. The example fetches DISTINCT values for one column in the table catgroup Sports Shows Concerts redshift select distinct multiple columns You can apply DISTINCT on … Read more

Duplicate rows in SQL

Duplicate rows in the table can result in data quality issues. Sometimes it is ok to have duplicate rows in the table as per business requirement. However if the duplicate rows are loaded into the table accidentally you must remove the duplicate rows. What are duplicate rows in SQL ? When the value of two … Read more