SQL SERVER – Correlated and Noncorrelated – SubQuery Introduction, Explanation and Example

A correlated subquery is an inner subquery which is referenced by the main outer query such that the inner query is considered as being executed repeatedly. Example: ----Example of Correlated Subqueries USE AdventureWorks; GO SELECT e.EmployeeID FROM HumanResources.Employee e WHERE e.ContactID IN ( SELECT c.ContactID FROM Person.Contact c WHERE MONTH(c.ModifiedDate)…
Read More

SQL SERVER – Fix: Error 130: Cannot perform an aggregate function on an expression containing an aggregate or a subquery

Fix: Error 130: Cannot perform an aggregate function on an expression containing an aggregate or a subquery Following statement will give the following error: “Cannot perform an aggregate function on an expression containing an aggregate or a subquery.” MS SQL Server doesn’t support it. USE PUBS GO SELECT AVG(COUNT(royalty)) RoyaltyAvg…
Read More