Posts

Showing posts from May, 2017

SQL Day 12: Joins

Image
LO1: Inner Join LO2: Outer Join LO3: Cross Join Prerequisite:  Creating Tables & Enforcing Primary and Foreign Key Joins are used to retrieve data from 2 or more tables based on given conditions. In SQL Server, there are different types of joins. Inner Join or Join Inner Join is used to retrieve the matching rows of two tables. When we use the inner join then it fetches the rows that are common in both the table and ignore the non-matching rows if any. Let’s say we have a tblEmployee tables which contain the DepartmentID column and tblDepartment table which contain different types of the department including locations. select * from tblEmployee select * from tblDepartment The tblEmployee table contains the department id’s for the employee and tblDepartment table contain the name of the department including the id of the department. Let’s say we need to find the department name of the employees, to do that we need to join the tblEmployee an...

Misc 01: Open a New Browser Window or Tab

Open a New Browser Window To open a new browser window as a popup, the below code need to be placed within body tag of your HTML code. <a href="javascript:void(0);" target="popup" onclick="window.open('LINK_TO_PAGE','name','width=600,height=400')">Open page in new window</a> Open a New Browser Tab To open a new browser tab, the below code need to be placed within body tag of your HTML code. <a href="LINK_TO_PAGE" target="_blank">Open page in new tab</a> Try by YourSelf Open page in new window Open page in new tab

SQL Day 11: Group By in SQL Server

Image
LO1: Grouping rows using Group By LO2: Filtering Groups LO3: Difference between Where and Having Clause Group By clause is used to group a selected set of rows into a set of summary rows by the values of one or more columns or expression. It is always used in conjunction with one or more aggregate functions. Let’s say we have a table tblEmployee which contains all the salary of employees including the cities. So if we need to find the maximum salary of employee we can use the MAX(Column_Name) aggregate function to find the highest salary of employees. select MAX(salary) from tblemployee In the same way, we can find the minimum salary and total salary of all the employees using different aggregate functions. select MIN(salary) as [Minimum Salary] from tblemployee select SUM(salary) as [Total Salary] from tblemployee Let’s say we have to find out the employee salary as per the different cities, to achieve this we need to use the Group B...

SQL Day 10: Select Statement – Part 2

Image
LO1: Operators and Wild Cards in SQL Server LO2: Joining Multiple Conditions using AND and OR Operator LO3: Sorting rows using Order By clause LO4: Selecting top n rows or top n percentage of rows Prerequisite:  SQL Day 10: Select Statement – Part 1 Operators and Wild Cards in SQL Server Operators: In previous part we have work with Equal to = and !=  <> operators. Similarly greater than and less than are used to filter the rows with the values greater than or less than as specified. Below is the list of Operators. IN Operator IN Operator is like multiple OR conditions so if you need to specify the list of values then use IN Operators. Let’s say you need to find the employee from the tblEmployee table whose age is 25, 30 and 28. It is possible by two ways either you specify multiple OR conditions or use IN operator. select * from tblEmployee where Age=25 or Age=30 or Age=28 select * from tblEmployee where Age IN (25,30,28) ...

SQL Day 10: Select Statement – Part 1

Image
LO1: Select Specific or All Columns LO2: Distinct Rows LO3: Filtering with Where Clause Prerequisite:  SQL Day 3: Creating Tables & Enforcing Primary and Foreign Key The Select statement is used to retrieve the all columns or specific columns from a table. Different Methods to Retrieve the Columns Using Select 1. Using * Sign When we use * sign is select statement then this will retrieve all the columns list of a table. Syntax: select * from (Table_Name) Example: select * from tblEmployee 2. Using all Column List Same as the * sign but can retrieve the selected columns as per the given list of columns. Syntax: select (Column_Names) from (Table_Name) Example: select ID, Name, Email from tblEmployee 3. Writing Select Query Graphically We can also generate the select statement graphically. To do that, you need to right-click on the table in Object Explorer and then go to the New Query Editor Window as per t...