Saturday 30 May 2015

JAVASCRIPT


JAVASCRIPT INTRODUCTION

"JavaScript is an object-oriented scripting language used to enable programmatic access to objects within both the client application and other applications (or) Client side Webpage validation."

JavaScript is the most popular scripting language on the internet, and works in all major browsers, such as Internet Explorer, Firefox, Chrome, Opera, and Safari.

Before you continue you should have a basic understanding of the following:

» HTML

If you want to study these subjects first learn HTML.

What is JavaScript?

» JavaScript was designed to add interactivity to HTML pages.

» JavaScript is a scripting language.

» A scripting language is a lightweight programming language.

» JavaScript is usually embedded directly into HTML pages.

» JavaScript is an interpreted language (means that scripts execute without preliminary compilation).

» Everyone can use JavaScript without purchasing a license.

The example below shows how to use JavaScript to write text on a web page:
Example

<html>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script></body>
</html>


The example below shows how to use JavaScript to write text on a web page:
Example

<html>
<body>
<script type="text/javascript">
document.write("Hello World!");
</script></body>
</html>


Where to Put the JavaScript

JavaScripts in a page will be executed immediately while the page loads into the browser. This is not always what we want. Sometimes we want to execute a script when a page loads, or at a later event, such as when a user clicks a button. When this is the case we put the script inside a function, you will learn about functions in a later chapter.

Scripts in <head>

Scripts to be executed when they are called, or when an event is triggered, are placed in functions.

Put your functions in the head section, this way they are all in one place, and they do not interfere with page content.

Example
<html>
<head>
<script type="text/javascript">
function message()
{
alert("This alert box was called with the onload event");
}
</script>
</head>
<body onload="message()">
</body>
</html>

Scripts <body>
If you don't want your script to be placed inside a function, or if your script should write page content, it should be placed in the body section.

Example
<html>
<head>
</head>
<body onload="message()">
<script type="text/javascript">
document.write("This message is written by JavaScript");
</script>
</body>
</html>

Scripts<head> and <body>
You can place an unlimited number of scripts in your document, so you can have scripts in both the body and the head section.

Example
<html>
<head>
<script type="text/javascript">
function message()
{
alert("This alert box was called with the onload event");
}
</script>
</head>

<body onload="message()">
<script type="text/javascript">
document.write("This message is written by JavaScript");
</script>
</body>




</html>

USERNAME VALIDATION USING JAVASCRIPT

Username validation:

Example

<html>

<head>

<script type="text/javascript">
function validation()
{
var a = document.form.name.value;
if(a=="")
{
alert("Please Enter Your Name");
document.form.name.focus();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return validation()">

<tr>

<td> Your Name:</td>

<td><input type="text" name="name""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>










Username Validation allows only Characters.


Example



<html>

<head>

<script type="text/javascript">
function validation()
{
var a = document.form.name.value;
if(a=="")
{
alert("Please Enter Your Name");
document.form.name.focus();
return false;
}
if(!isNaN(a))
{
alert("Please Enter Only Characters");
document.form.name.select();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return validation()">

<tr>

<td> Your Name:</td>

<td><input type="text" name="name""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>






Username Validation allows only Limited Characters.


Example



<html>

<head>

<script type="text/javascript">
function validation()
{
var a = document.form.name.value;
if(a=="")
{
alert("Please Enter Your Name");
document.form.name.focus();
return false;
}
if(!isNaN(a))
{
alert("Please Enter Only Characters");
document.form.name.select();
return false;
}
if ((a.length < 5) || (a.length > 15))
{
alert("Your Character must be 5 to 15 Character");
document.form.name.select();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return validation()">

<tr>

<td> Your Name:</td>

<td><input type="text" name="name""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>








PASSWORD VALIDATION USING JAVASCRIPT












Example



<html>

<head>

<script type="text/javascript">
function validation()
{
var a = document.form.pass.value;
if(a=="")
{
alert("Please Enter Your Password");
document.form.pass.focus();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return validation()">

<tr>

<td> password:</td>

<td><input type="text" name="pass""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>







Password Validation (Hiding Your password)


Example



<html>

<head>

<script type="text/javascript">
function validation()
{
var a = document.form.pass.value;
if(a=="")
{
alert("Please Enter Your Password");
document.form.pass.focus();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return validation()">

<tr>

<td> Password:</td>

<td><input type="password" name="pass""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>









Password Validation allows only Limited Characters or integers.


Example



<html>

<head>

<script type="text/javascript">
function validation()
{
var a = document.form.pass.value;
if(a=="")
{
alert("Please Enter Your Password");
document.form.pass.focus();
return false;
}
if ((a.length < 4) || (a.length > 8))
{
alert("Your Password must be 4 to 8 Character");
document.form.pass.select();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return validation()">

<tr>

<td> Passsword:</td>

<td><input type="password" name="pass""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>









EMAIL VALIDATION USING JAVASCRIPT








Email validation:


Example



<html>

<head>

<script type="text/javascript">
function validation()
{
var a = document.form.email.value;
if(a=="")
{
alert("Please Enter Your Password");
document.form.email.focus();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return validation()">

<tr>

<td> Email:</td>

<td><input type="text" name="email""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>







Email Validation (Email filter /@\ and /.\)


Example



<html>

<head>

<script type="text/javascript">
function ValidateContactForm()
{
var email = document.ContactForm.Email;
if (email.value == "")
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
if (email.value.indexOf("@", 0) < 0)
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
if (email.value.indexOf(".", 0) < 0)
{
window.alert("Please enter a valid e-mail address.");
email.focus();
return false;
}
}
</script></head>

<body>

<form name="ContactForm" method="post" onsubmit="return ValidateContactForm();">

<tr>

<td> Email:</td>

<td><input type="text" name="Email""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>










Email Validation (Email filter /@\ and /.\)


Example



<html>

<head>

<script type="text/javascript">
function validation()
{
var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i
var b=emailfilter.test(document.form2.mailid.value);
if(b==false)
{
alert("Please Enter a valid Mail ID");
document.form2.mailid.focus();
return false;
}
}
</script></head>

<body>

<form name="form2" method="post" onsubmit="return validat()">

<tr>

<td> Email-ID:</td>

<td><input type="text" name="mailid"></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>




PHONE NUMBER VALIDATION USING JAVASCRIPT




Phone validation:


Example



<html>

<head>

<script type="text/javascript">
function validation()
{
var a = document.form.phone.value;
if(a=="")
{
alert("Please Enter Your Phone Number");
document.form.phone.focus();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return validation()">

<tr>

<td> Phone:</td>

<td><input type="text" name="phone""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>






Phoneno Validation


Example



<html>

<head>

<script type="text/javascript">
function Validation()
{
var a = document.form.phone.value;
if(a=="")
{
alert("please Enter the Contact Number");
document.form.phone.focus();
return false;
}
if(isNaN(a))
{
alert("Enter the valid Phone Number(Like : 044-42046569)");
document.form.phone.focus();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return Validation()">

<tr>

<td> Phone No:</td>

<td><input type="text" name="phone""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>









MOBILE NUMBER VALIDATION USING JAVASCRIPT





Mobile validation:


Example



<html>

<head>

<script type="text/javascript">
function validation()
{
var a = document.form.phone.value;
if(a=="")
{
alert("Please Enter Your Mobile Number");
document.form.phone.focus();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return validation()">

<tr>

<td> Mobile:</td>

<td><input type="text" name="phone""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>









Mobile Number Validation


Example



<html>

<head>

<script type="text/javascript">
function Validation()
{
var a = document.form.phone.value;
if(a=="")
{
alert("please Enter the Contact Number");
document.form.phone.focus();
return false;
}
if(isNaN(a))
{
alert("Enter the valid Mobile Number(Like : 9566137117)");
document.form.phone.focus();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return Validation()">

<tr>

<td> Mobile No:</td>

<td><input type="text" name="phone""></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>





Mobileno Validation


Example



<html>

<head>

<script type="text/javascript">
function Validation()
{
var a = document.form.phone.value;
if(a=="")
{
alert("please Enter the Contact Number");
document.form.phone.focus();
return false;
}
if(isNaN(a))
{
alert("Enter the valid Mobile Number(Like : 9566137117)");
document.form.phone.focus();
return false;
}
if((a.length < 1) || (a.length > 10))
{
alert(" Your Mobile Number must be 1 to 10 Integers");
document.form.phone.select();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return Validation()">

<tr>

<td> Mobile No:</td>

<td><input type="text" name="phone"></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>






ADDRESS AND TEXTAREA VALIDATION USING JAVASCRIPT









Textarea validation:


Example



<html>

<head>

<script type="text/javascript">
function validation()
{
var a = document.form.address.value;
if(a=="")
{
alert("Please Enter Your Details Here");
document.form.address.focus();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return validation()">

<tr>

<td> Address:</td>

<td><textarea name="address" cols="30" rows="4"></textarea></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>









Textarea Validation


Example



<html>

<head>

<script type="text/javascript">
function Validation()
{
var a = document.form.address.value;
if(a=="")
{
alert("please Enter the details");
document.form.address.focus();
return false;
}
if((a.length < 20) || (a.length > 100))
{
alert(" Your textarea must be 20 to 100 characters");
document.form.address.select();
return false;
}
}
</script></head>

<body>

<form name="form" method="post" onsubmit="return Validation()">

<tr>

<td> Address:</td>

<td><textarea name="address" cols="60" rows="10"></textarea></td>

</tr>

<tr>

<td></td>

<td><input type="submit" name="sub" value="Submit"></td>

</tr>

</form>

</body>

</html>




RADIO BUTTON VALIDATION USING JAVASCRIPT




RadioButton validation:


Example



<html>

<head>

<script LANGUAGE="JavaScript">
function ValidateForm(form){
ErrorText= "";
if ( ( form.gender[0].checked == false ) && ( form.gender[1].checked == false ) )
{
alert ( "Please choose your Gender: Male or Female" );
return false;
}
if (ErrorText= "") { form.submit() }
}
</script></head>

<body>

<form name="feedback" action="#" method=post>

Your Gender: <input type="radio" name="gender" value="Male"> Male

<input type="radio" name="gender" value="Female"> Female

<input type="button" name="SubmitButton" value="Submit" onClick="ValidateForm(this.form)">

<input type="reset" value="Reset">

</form>

</body>

</html>





The Output is Shown Here:

Your Gender: Male Female







RadioButton Validation


Example



<html>

<head>

<script type="text/javascript">
function checkButton(){
if(document.form1.button1.checked == true){
alert("Box1 is checked");
} else if(document.form1.button2.checked == true){
alert("Box 2 is checked");
}
}
</script></head>

<body>

<form name="form1">

<input type="radio" name=button1>Box 1

<br> <input type="radio" name=button2 CHECKED>Box 2

<br> <INPUT type="button" value="Get Checked" onClick='checkButton()'>

</form>

</body>

</html>








The Output is Shown Here:



Box 1

Box 2






RadioButton Validation


Example



<html>

<head>

<script type="text/javascript">
function evalGroup()
{
var group = document.radioForm.myRadio;
for (var i=0; i<group.length; i++) {
if (group[i].checked)
break;
}
if (i==group.length)
return alert("No radio button is checked");
alert("Radio Button " + (i+1) + " is checked.");
}
</script></head>

<body>

<form name="radioForm">

Radio Button 1: <input type="radio" name="myRadio" /><br />

Radio Button 2: <input type="radio" name="myRadio" /><br />

Radio Button 3: <input type="radio" name="myRadio" /><br />

Radio Button 4: <input type="radio" name="myRadio" /><br /><br />

<input type="button" value="Eval Group" onclick="evalGroup()" />

</form>

</body>

</html>








The Output is Shown Here:



Radio Button 1:

Radio Button 2:

Radio Button 3:

Radio Button 4:
















CHECKBOX VALIDATION USING JAVASCRIPT




Checkbox validation:


Example



<html>

<head>

<script LANGUAGE="JavaScript">
function ValidateForm(form){
ErrorText= "";
if ( ( form.gender[0].checked == false ) && ( form.gender[1].checked == false ) )
{
alert ( "Please choose your Gender: Male or Female" );
return false;
}
if (ErrorText= "") { form.submit() }
}
</script></head>

<body>

<form name="feedback" action="#" method=post>

Your Gender: <input type="radio" name="gender" value="Male"> Male

<input type="checkbox" name="gender" value="Female"> Female

<input type="checkbox" name="SubmitButton" value="Submit" onClick="ValidateForm(this.form)">

<input type="reset" value="Reset">

</form>

</body>

</html>





The Output is Shown Here:

Your Gender: Male Female







Checkbox Validation


Example



<html>

<head>

<script type="text/javascript">
function checkButton(){
if(document.form1.button1.checked == true){
alert("Box1 is checked");
} else if(document.form1.button2.checked == true){
alert("Box 2 is checked");
}
}
</script></head>

<body>

<form name="form1">

<input type="chechbox" name=button1>Box 1

<br> <input type="chechbox" name=button2 CHECKED>Box 2

<br> <INPUT type="button" value="Get Checked" onClick='checkButton()'>

</form>

</body>

</html>








The Output is Shown Here:



Box 1

Box 2






Checkbox Validation


Example



<html>

<head>

<script type="text/javascript">
function evalGroup()
{
var group = document.radioForm.myRadio;
for (var i=0; i<group.length; i++) {
if (group[i].checked)
break;
}
if (i==group.length)
return alert("No Checkbox is checked");
alert("Radio Button " + (i+1) + " is checked.");
}
</script></head>

<body>

<form name="radioForm">

Checkbox 1: <input type="chechbox" name="myRadio" /><br />

Chechbox 2: <input type="chechbox" name="myRadio" /><br />

Chechbox 3: <input type="chechbox" name="myRadio" /><br />

Chechbox 4: <input type="chechbox" name="myRadio" /><br /><br />

<input type="button" value="Eval Group" onclick="evalGroup()" />

</form>

</body>

</html>








The Output is Shown Here:



chechbox 1:

chechbox 2:

chechbox 3:

chechbox 4:









Checkbox Validation


Example



<html>

<head>

<script type="text/javascript">
var myFlag = false
function initValue() {
myFlag = document.forms[0].sizes[0].checked;
}
function sh(form) {
for (var i = 0; i < form.sizes.length; i++) {
if (form.sizes[i].checked) {
break;
}
}
alert(form.sizes[i].value);
}
function setmyFlag(setting) {
myFlag = setting;
}
function exitMsg() {
if (myFlag) {
alert("exit message.");
}
}
</script> </head>

<body>

<form >

<input type="checkbox" name="sizes" value="1" checked="checked" onclick="setmyFlag(true)" />1

<input type="checkbox" name="sizes" value="2" onclick="setmyFlag(false)" />2

<input type="checkbox" name="sizes" value="7" onclick="setmyFlag(false)" /&g <input type="checkbox" name="sizes" value="5" onclick="setmyFlag(false)" />5

t;5

<input type="button" name="Viewer" value="View" onclick="sh(this.form)" />

</form>

</body>

</html>








The Output is Shown Here:



1 2 7 5










SELECT INDEX VALIDATION USING JAVASCRIPT




Select Index validation:


Example



<html>

<head>

<script LANGUAGE="JavaScript">
function validation()
{
if(document.login.type.selectedIndex==0)
{ alert("Please select your member type");
document.login.type.focus();
return false;
}
return true;
}
</script></head>

<body>

<form name="login" method="post" action="#" onsubmit="return validation();">

<select name="type" class="texta1">

<option name="sel" value="Selected">Select Type</option>

<option name="fr" value="Freshers">Freshers</option>

<option name="ex" value="Experienced">Experienced</option>

<option name="un" value="Under_Studying">Under_Studying</option>

</select>

</form>

</body>

</html>





The Output is Shown Here:











Drog and Drop Validation


Example



<html>

<head>

<script type="text/javascript">
function handleDragDropEvent(oEvent) {
var oTextbox = document.getElementById("txt1");
oTextbox.value += oEvent.type + "\n";
</script></head>

<body>

<P>Try dragging the text from the left textbox to the right one.</p>

<P>

<input type="text" value="drag this text"

ondragstart="handleDragDropEvent(event)"

ondrag="handleDragDropEvent(event)"

ondragend="handleDragDropEvent(event)" />

<input type="text"

ondragenter="handleDragDropEvent(event)"

ondragover="handleDragDropEvent(event)"

ondragleave="handleDragDropEvent(event)"

ondrop="handleDragDropEvent(event)" />

</p>

<P><textarea rows="10" cols="25" readonly="readonly" id="txt1"></textarea></p>

</body>

</html>








The Output is Shown Here:



Try dragging the text from the left textbox to the right one.




























Friday 22 May 2015

Can we join two tables without primary foreign key relation IN SQL

Yes, we can join two tables without primary foreign key relation as long as the column values involved in the join can be converted to one type.
Create Departments and Employees tables using the SQL script below
Create table Departments
(
     ID int not null,
     Name nvarchar(50),
     Location nvarchar(50)
)
GO

Create table Employees
(
     ID int,
     Name nvarchar(50),
     Gender nvarchar(50),
     Salary int,
     DepartmentId int
)
GO

Insert into Departments values (1, 'IT', 'New York')
Insert into Departments values (2, 'HR', 'London')
Insert into Departments values (3, 'Payroll', 'Sydney')
GO

Insert into Employees values (1, 'Mark', 'Male', 60000, 1)
Insert into Employees values (2, 'Steve', 'Male', 45000, 3)
Insert into Employees values (3, 'Ben', 'Male', 70000, 1)
Insert into Employees values (4, 'Philip', 'Male', 45000, 2)
Insert into Employees values (5, 'Mary', 'Female', 30000, 2)
Insert into Employees values (6, 'Valarie', 'Female', 35000, 3)
Insert into Employees values (7, 'John', 'Male', 80000, 1)
GO

Notice that
 ID column in Departments table is not the primary Key and DepartmentIdcolumn in Employees table is not the foreign key. But we can still join these tablesusing ID column from Departments table and DepartmentId column from Employees table, as both the columns involved in the join have same data type i.e int.

Query:

Select Employees.Name as EmployeeName, Departments.Name asDepartmentName
from Employees

join Departments on Departments.ID = Employees.DepartmentId

The above query produces the following output 

The obious next question is, if primary foreign key relation is not mandatory for 2 tables to be joined then what is the use of these keys?

Primary key enforces uniqueness of values over one or more columns.
 Since ID is not a primary key in Departments table, 2 or more departments may end up having same ID value, which makes it impossible to distinguish between them based on the ID column value.

Foreign key enforces referential integrity.
 Without foreign key constraint on DepartmentId column in Employees table, it is possible to insert a row into Employees table with a value for DepartmentId column that does not exist in Departments table.

The following insert statement, successfully inserts a new Employee into Employees table whose DepartmentId is 100. But we don't have a department with ID = 100 in Departments table. This means this employee row is an orphan row, and the referential integrity is lost as result
Insert into Employees values (8, 'Mary', 'Female', 80000, 100)

If we have had a
 foreign key constraint on DepartmentId column in Employees table,the following insert statement would have failed with the following error.

Msg 547, Level 16, State 0, Line 1
The INSERT statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database "Sample", table "dbo.Departments", column 'ID'.

Let's now see how to enforces referential integrity using foreign key constraint.
Step 1 :
 Delete the employee record from Employees table where DepartmentId = 100
Delete from Employees where DepartmentId = 100

Step 2 : Mark ID column as primary key in Departments table
alter table Departments
add primary key (ID)

Setp 3 : Mark DepartmentId column as foreign key in Employees table
Alter table Employees
add foreign key(DepartmentId)
references Departments(ID)

Step 4 : Execute the following insert statement. Notice that an error is raised.
Insert into Employees values (8, 'Mary''Female', 80000, 100)

--Other SQL Queries used in the demo
Create Table T1
(
     ID int,
     T1Column1 nvarchar(20)
)
GO

Insert into T1 values (1, 'T1 Value 1')
Insert into T1 values (2, 'T1 Value 2')
GO

Create Table T2
(
     ID decimal,
     T2Column1 nvarchar(20)
)
GO

Insert into T2 values (1, 'T2 Value 1')
Insert into T2 values (2, 'T2 Value 2')
GO

Select T1.T1Column1, T2.T2Column1
from T1
join T2 on T1.ID = T2.ID

Alter Table T2 Alter Column ID nvarchar(3)

Insert into T2 values('XX', 'T2 Value 3')



How to retrieve all the Department Names and the total number of Employees with in each department in SQL


SQL Script to create the required tables
Create Table Departments
(
     DepartmentID int primary key,
     DepartmentName nvarchar(50)
)
GO

Create Table Employees
(
     EmployeeID int primary key,
     EmployeeName nvarchar(50),
     DepartmentID int foreign key references Departments(DepartmentID)
)
GO

Insert into Departments values (1, 'IT')
Insert into Departments values (2, 'HR')
Insert into Departments values (3, 'Payroll')
Insert into Departments values (4, 'Admin')
GO

Insert into Employees values (1, 'Mark', 1)
Insert into Employees values (2, 'John', 1)
Insert into Employees values (3, 'Mike', 1)
Insert into Employees values (4, 'Mary', 2)
Insert into Employees values (5, 'Stacy', 2)

GO

SQL Query with Right Join
Select DepartmentName, Count(Employees.DepartmentID) as TotalEmployees
From Employees
Right Join Departments
ON Departments.DepartmentID = Employees.DepartmentID
Group By DepartmentName
Order By TotalEmployees