MERGE in Sql Server

From Sql server 2012 we can merge two tables. We can map data from one table to another table. If record exists can do a update and if not insert operation can be done. Syntax Create two tables and Insert some records Then do Merge Now view TargetTable Data   Advertisements

Sub Query in Sql

What is subquery? Subquery is  just a query inside of a query. Why Subquery? Break down complex logic Simplify reading Subqueries can be replaced by joins. But some times Joins can be complex. Other thing is we are not allowed to put aggregates in WHERE. But we can put it aggreagates inside subquery . Where to Use? We can put sub queries in  three main places in query. SELECT FROM WHERE Using in SELECT Access informations from tables  withing select query Query must return a single(scalar) value Creates a dynamic table. Useful for  breaking down queries. Query must be aliased. Note : I have used Adventureworks 2012 database for following queries  Using with FROM With WHERE Useful for comparing values from other tables Predicates used with subqueries IN Confirm column value exist in subquery Similar to inner join EXISTS Returns true if subquery returns value Used with correlated queries Correlated subquery Pass outer query column into subquery ALL Compares column

read more Sub Query in Sql