Saturday, 7 March 2015






REPEATED  QUESTIONS IN .NET INTERVIEW 



Answer: 
 
This is a great c# interview question , but .NET professionals tend to answer this question in one liners like i am a developer , project manager.
In  today's world people expect professionals who can do multitasking. The best way to approach the answer is by explaining what things did you do in the complete SDLC cycle. Below goes my version of the answer , you can tailor the same as per your needs.
My main role in the project was coding , unit testing and bug fixing. Said and done that i was involved in all phases of the project.

I worked with the business analyst in the requirement phase to gather requirements and was a active member in writing use cases.

I also assisted the technical architect in design phase. In design phase i helped the architect in proof of concept  and putting down the technical design document.

My main role was in coding phase where i executed project with proper unit testing.

In system integration test and UAT I was actively involved in bug fixing.
Other than the project i help COE team for any kind of RND and POC work.
In case you are doing some extra activities in the company like helping COE , presales team or any other initiative do speak about the same.


Answer: 
 
This is normally the first .NET interview question which pops up in .NET and C# interviews. Personally i think your full  .NET interview ahead depends on how you will answer this question.
Common mistakes :- Many developers make a common mistake of answering this question by saying that we have used C# , SQL server , ASP.NET etc. But please do note that the question is, what is the architecture of your project and not technology.
So a typical answer will be something as below. Please note your answer will vary as per your architecture and structure.
"My current architecture is a simple 3 tier architecture with UI in ASP.NET , middle layer are simple .NET classes and DAL is using enterprise application blocks.
The UI  is responsible to take user inputs , all my business validations are centrally located in middle layer and the data access layer is responsible to execute stored procedured and SQL queries to SQL Server.
Strongly typed business objects are used to pass data from one layer to other layer. The database of the project is in a 3rd normal form."

So first start with the overall architecture , talk about each layer , how data is passed between each layer and the database design structure.

One very important tip if you can draw a diagram and explain....I think you have the job.



Answer: 
This is a great  and the most asked ASP.NET interview question. Out of 100 .NET interviews at least 70 interviewer will ask this question. The answer is very simple but the problem with the answer is that developers forget the  sequence of ASP.NET page life cycle.
The best way to remember this answer is by remembering the word SILVER.
S (Well this word is just to make up the word , you can just skip this.)
I (Init)
L (Load)
V (Validate)
E (Event)
R (Render)

You can also see the video on Generics at http://youtu.be/7bKhAJpY9ho?hd=1

This is one of the most important typical question, which is asked in most of the interviews to check whether you know about generic.Generic help us to create flexible strong type collection.
Generic basically separates the logic from the data type in order maintain better reusability, better maintainability etc.

Lets see an simple example to understand how exactly generic separate logic from data type.
class Check
    {
        public bool Compare(UNKNOWNDATATYPE i, UNKNOWNDATATYPE j)
        {
            if (i.Equals(j))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
In above code snippet, I have created a class called as "Check" with UNKNOWNDATATYPE so that, I can define different data types at run time. Now, in below code you can see that I have created two object of Check class with two different datatypes(int,string).
 
class Program
    {
        static void Main(string[] args)
        {
            Check ObjCheck = new Check();    //here i have defined int datatype
            bool b1 = ObjCheck.Compare(1, 1);
            Check Obj1 = new Check();    //here i have defined string datatype
            bool b2 = Obj1.Compare("feroz", "kalim");
            Console.WriteLine("Numeric Comparison Result:" + b1);
            Console.WriteLine("String Comparison Result:"+ b2);
            Console.ReadLine();
        }
    }
Below is the full code snippet for the same so that you can try it by yourself and see the resultant output.
 
class Program
    {
        static void Main(string[] args)
        {
            Check ObjCheck = new Check();
            bool b1 = ObjCheck.Compare(1, 1);
            Check Obj1 = new Check();
            bool b2 = Obj1.Compare("feroz", "kalim");
            Console.WriteLine("Numeric Comparison Result:" + b1);
            Console.WriteLine("String Comparison Result:"+ b2);
            Console.ReadLine();
        }
    }

    class Check
    {
        public bool Compare(UNKNOWNDATATYPE i, UNKNOWNDATATYPE j)
        {
            if (i.Equals(j))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }

Answer: 
 
MVC is one of the most used architecture pattern in ASP.NET and this is one of those ASP.NET interview question to test that do you really understand the importance of model view controller.
  • It provides a clean separation of concerns between UI and model.
  • UI can be unit test thus automating UI testing.
  • Better reuse of views and model. You can have multiple views which can point to the same model and also vice versa.
  • Code is better organized.
Answer: 

MVVM is a UI design pattern. The main use of this pattern to remove UI cluttered code like bindings , synchronization etc.In this pattern we create a extra class called as view model  or model which acts as a bridge between model and view. The view sends the actions and data to the model view class who in turns sends the data to model. Any changes in the model is replicated or informed to the UI using the INotifyPropertyChanged interface.

Which design patterns have you used in your project ?
click here to see video of factory design pattern  http://youtu.be/yDEmb5XYc_s
Answer: 

First thing what ever you say , for heaven sake do not say we had used all design patterns ;-) . Look at your project and see which design pattern have you used. Almost all projects use design patterns knowingly or unknowingly , until the project is complete disorganized.

While explaining do ensure to make a 1 line comment atleast to say why that design pattern was used.

Below goes a decent answer of explaining things collectively. Please note answer will change as per your project implementation.
In my current project we had used MVCSingletonfactory , iterator   and template pattern.

My project was tier architecture, divided in to 3 main sections, UI, Business layer and data access layer.

At the presentation level we had used MVC pattern, so the UI and model was separated using controller class.

To share common data across all tiers we had used the singleton pattern.

Factory classes where used between each layer for decoupling and centralizing object creation to avoid code complication.

Iterator pattern was used to browse through middle tier objects thus providing a tight encapsulation.

The   middle tier objects and their child objects where standardized using template pattern for consistent vocabulary and naming convention for business objects.


What is trigger and different types of Triggers?
Answer: 

Trigger is a SQL server code, which execute when a kind of action on a table occurs like insert, update and delete. It is a database object which is bound to a table and execute automatically.
Triggers are basically of two type's namely "After Triggers" and "Instead of Triggers".
1.After Triggers:- this trigger occurs after when an insert, update and delete operation has been performed on a table.
"After Triggers" are further divided into three types
AFTER INSERT Trigger.
AFTER UPDATE Trigger.
AFTER DELETE Trigger.
Let us consider that we have the following two tables.
Create "Customer" table with the following field as you see in the below table.

Cust_IDCust_CodeCust_Name  Cust_Salary
1A-31Moosa4500
2A-09Feroz5000
3A-16Wasim4000

Create "Customer_Audit" table with the following field as you see in the below table.

Cust_ID  Cust_NameOperation_PerformedDate_Time

The main purpose of creating "Customer_Audit" table is to record the data which occurs on the "Customer" table with their respective operation and date-time.
Let's begin with "After Insert Trigger":- This trigger fire after an insert operation performed on a table.
Let us see the example of "After Insert Trigger" for better understanding.
Query:-
Create Trigger TrigInsert on Customer
For insert as
declare @Cust_ID int;
declare @Cust_Name varchar(100);
declare @Operation_Performed varchar(100);
select @Cust_ID=i.Cust_ID from inserted i;
select @Cust_Name=i.Cust_Name from inserted i;
set @Operation_Performed='Inserted Record -- After Insert Trigger';
insert into Customer_Audit
(Cust_ID,Cust_Name,Operation_Performed,Date_Time)
values(@Cust_ID,@Cust_Name,@Operation_Performed,getdate());
PRINT 'AFTER INSERT trigger fired.'
Now, insert a record into Customer table:
Query:- insert into Customer values ('A-10','Danish')
Once the insert statement is successfully done, the record is inserted into the "Customer" table and the "After Trigger" (TrigInsert) is fired and the same record is also stored into "Cutomer_Audit" table.
To see the record in "Customer_Audit" table write query as below:-
Query:- select * from Customer_Audit
Cust_ID  Cust_NameOperation_PerformedDate_Time
4DanishInserted Record -- After Insert Trigger2011-04-06 19:46:56.390
You can see that the same record is seen in the "Customer_Audit" table with Operation_performed and the date_time when it was updated.
Now let's see for "After Update Trigger":-This trigger fire after an update operation performed on a table.
Let us see the example of "After Update Trigger" for better understanding.
Query:- Create trigger TrigUpdate on Customer
For Update as
declare @Cust_ID int;
declare @Cust_Name varchar(100);
declare @Operation_Performed varchar(100);
select @Cust_ID=i.Cust_ID from inserted i;
select @Cust_Name=i.Cust_Name from inserted i;
set @Operation_performed='Inserted Record -- After Insert';
f update(Cust_Name)
set @Operation_Performed='Updated Record -- After Update Trigger.';
insert into Customer_Audit
(Cust_ID,Cust_Name,Operation_Performed,Date_Time)
values(@Cust_ID,@Cust_Name,@Operation_Performed,getdate())
PRINT 'AFTER UPDATE Trigger fired.'
Now, update a record into "Customer" table:-
Query:- update Customer set Cust_Name = 'Khan Wasim' where Cust_Code like 'A-16'
The record is updated into the Customer table and the TrigUpdate is fired and it stores a record into
"Cutomer_audit" table.
To see the record Customer_Audit table write query for that.
Query:- select * from Customer_Audit
Cust_ID  Cust_NameOperation_PerformedDate_Time
4DanishInserted Record -- After Insert Trigger2011-04-06 19:46:56.390
3Khan WasimUpdated Record -- After Update Trigger2011-04-06 20:03:05.367
Now for, "After Delete Trigger":-This trigger fire after a delete operation performed on a table.
In a similar way, you can code "After Delete trigger" on the table.
2.Instead of Triggers:- this trigger fire before the DML operations occur, first inserted and deleted get flourished and then trigger fires
"Instead of Triggers" are further divided into three types
Instead of INSERT Trigger.
Instead of UPDATE Trigger.
Instead of DELETE Trigger.
Let us see the example of "Instead of UPDATE Trigger" for better understanding.
Query:-
CREATE TRIGGER trgInsteadOfUpdate ON Customer
INSTEAD OF update
AS
declare @cust_id int;
declare @cust_name varchar(100);
declare @cust_salary  int;
select @cust_id=d. Cust_ID from deleted d;
select @cust_name=d. Cust_Name from deleted d;
select @cust_salary =d.Cust_Salary from deleted d;
BEGIN
if(@cust_salary >4500)
begin
RAISERROR('Cannot delete where salary > 4500',16,1);
ROLLBACK;
end
else
begin
delete from Customer where Cust_ID =@cust_id;
COMMIT;
insert into Customer_Audit(Cust_ID,Cust_Name,Cust_Salary,Operation_Performed,Date_Time)
values(@cust_id,@cust_name,@cust_salary,'Updated -- Instead Of Updated Trigger.',getdate());
PRINT 'Record Updated -- Instead Of  Updated Trigger.'
end
END
Now, update a record into "Customer" table:-
Query:- update Customer set Cust_Name = 'Khan Wasim' where Cust_Code like 'A-09'
When you try to update Customer table it will raise an error as we have use Instead of Update trigger.
Error:- Server: Msg 50000, Level 16, State 1, Procedure trgInsteadOfUpdate, Line 15
Cannot update where salary > 4500
In a similar way, you can code "Instead Delete trigger" and "Instead Insert trigger" on the table.

Answer: 
Let's demonstrate an example to prove that how arrays are faster than arraylist for that go to visual studio and create a simple window application with a button and two labels like below diagram.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
Below is the code snippet.
using System.Collections;// import this namespace to access arraylist.
using System.Diagnostics;// import this namespace to access Stopwatch.
namespace ArrayandArrayList
{
    public partial class Form1 : Form
    {
        int[] Array = new int[1000]; // here array is declared.
        ArrayList objArraylist = new ArrayList();// here array list is declared.
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Stopwatch objWatch = new Stopwatch();
            Stopwatch objWatch1 = new Stopwatch();
            objWatch.Start();
            for(int i=0;i<1000;i++)
            {
                Array[i] = DateTime.Now.Second;
            }
            foreach (int i in Array)
            {

            }
            objWatch.Stop();
            label1.Text = objWatch.ElapsedTicks.ToString();
            objWatch1.Start();
            for (int i = 0; i < 1000; i++)
            {
                objArraylist.Add(DateTime.Now.Second.ToString());
            }
            foreach (object i in objArraylist)
            {
            }
            objWatch1.Stop();
            label2.Text = objWatch1.ElapsedTicks.ToString();
        }
    }
}
In the above code, I have used Stopwatch to record the time taken by the array and  arraylist to performance actions.
The Output look like below diagram.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
Conclusion: -As in ArrayList lots of Boxing and UnBoxing are done therefore its performance is slower than Array because in Array there is no type casting.
Answer:
Array
 
ArrayList
 
They are fixed length.
 
They are resizable and variable length.
 
They are compiled strong type collection.
 
They are flexible and can accommodate any data types.
 
Because arrays are of fixed size and strong type collection performance is faster.
 
In arraylist lots of boxing and unboxing are done there for its performance is slower.
 
Let's see an example to prove the above differences.

The below is how we declare Array.
String [ ] str = new String [5]; // here you see that the length is fixed as [5] and the data type is also defined as string.
Now, see how you can declare ArrayList.
ArrayList   str = new ArrayList (); // here you see that the length is not fixed and is not tied up with a data type.
If you go to add data to an ArrayList you can see it takes object which is a very generic type.Due to this boxing, unboxing or casting are done.
In other words data moves from stack to heap or heap to stack.If you look at Array as they are strong types boxing and unboxing are completely avoided.
Therefore, Array performance is faster as compared to ArrayList. 
The below diagram gives a better idea of the differences between Array and ArrayList.
 .net interview questions,c# interview questions,ASP .NET interview questions, SQL server interview questions

PreRender: -PreRender is an event which is used for modifying server controls just  before sending them to the client.

Render: -Render is an method which actually puts the HTML output to the response stream.

Lets see an simple example to get an better idea, below is the code snippet for the same.
To use PreRender event, we have to override it and can make neccessary changes to the controls we want to.
protected override void On PreRender (EventArgs e)
{
 foreach (GridViewRow row in GridView1.Rows)
  {
      row.ForeColor = Color.Blue;
  }        
}

In the above code snippet, I have override the PreRender event and just changed the forecolor of the GridView.

Now lets see how we can code for Render. Below is the code snippet for the same, in which I have override the Render and using "HtmlTextWriter" just displayed a simple HTML text output.
protected override void Render (HtmlTextWriter writer)
{
   writer. Write ("This displays the grid in blue color");
   base. Render (writer);
}
Below is the full code snippet so that you can try it by yourself and see the respective result.
 
using System.Drawing;
using System.Collections;

namespace Data
{
    public class Customer
    {
        public string CustomerCode { set; get; }
        public string CustomerName { set; get; }
    }
    public partial class WebForm1 : System.Web.UI.Page
    {
     
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadGrid();
        }
        public void LoadGrid()
        {
            ArrayList objArray = new ArrayList();
            Customer ObjCustomer = new Customer();
            ObjCustomer.CustomerCode = "1001";
            ObjCustomer.CustomerName = "shiv";
            objArray.Add(ObjCustomer);
            ObjCustomer = new Customer();
            ObjCustomer.CustomerCode = "1002";
            ObjCustomer.CustomerName = "Feroz";
            objArray.Add(ObjCustomer);
            GridView1.DataSource = objArray;
            GridView1.DataBind();
        }
        protected override void OnPreRender(EventArgs e)
        {
            foreach (GridViewRow row in GridView1.Rows)
            {
                row.ForeColor = Color.Blue;
            }
         
        }
        protected override void Render(HtmlTextWriter writer)
        {
            writer.Write("This displays the grid in blue color");
            base.Render(writer);
        }
    }
}
In the above code snippet, I have used prerender event to change the forecolor of the girdview before the gridview is displayed on the client browser and I have override the render method to display the html output to the response stream.

PreRender event executed before the render method gets called which creates the HTML code using the HtmlWriter.so in other words prerender event fires first and do the necessary changes to the server control and later the render method is called.

In below diagram you can see that the gridview forecolor is been changed because of the prerender event and the render method display the html output using html writer.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
This is one of the most typical question asked by the interviewers.
Let's us assume that we have the following two table of Product and Vendor with their respective fields like below.
ProductId    ProductName    Cost            //Product table
VendorID     VendorName     ProductId     //Vendor table 
Now let's begin with how you can design one to one relationship between these two tables.
One to One relationship:-
Below diagram show one to one relationship between Product and Vendor table.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
In the above Product table "ProductId" is defined as a primary key and in the Vendor table "ProductId" is defined as foreign key with reference to the "ProductId" of the Product table.
In this way you can achieve one to one relationship.
One to Many relationship:-
Now we want to define one to many relationship on Vendor and Product table.
In this many records in one table correspond to the one record in another table.
Example: Every one vendor can have multiple products. So there exist one-to-many relationships between Vendor and Product table.
In order to define one to many relationship you have to add one column name as VendorId in Product table which is foreignkey reference to VendorId of Vendor table.
Below diagram show one to many relationship on Product and Vendor table.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
Many to Many relationship:-
In this, one record in one table corresponds to many rows in another table and also vice-versa.
For instance: In a company, one vendor can sale many products and also one product can be sold by many Vendors.
Given below diagram is a sample of many-to-many relationship. For defining many to many we have to add one more table VendorProduct which is linked to the primary key of Product and Vendor tables.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions

FxCop is a code analyzer tool which runs on .NET dll file it helps you to analyze the quality of .NET code. (Quality in terms of coding standards, best practices etc.)

To view how exactly the FxCop do code review you need to download the FxCop from MSDN site and install it on your local host machine.

As FxCop runs on .NET dll file you need to add the dll file of your project on which you want to do code review.
The below diagram will give you an idea of how will you add the dll file in FxCop.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions

Once you click on the Add Target button just browse to the dll file you want to do code review like below diagram.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
After adding the dll file to FxCop, Now click on the Analze button and you will see the window like below diagram with the respective result.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
Once you click on analyze button it runs all the rules on the selected dll file and shows that what kind of rules are broken by the dll file.As you see in the above diagram some of the rules are broken by the selected dll file.
You can take these rules and try to close your project structure in standard manner and improve the quality of your project.

 
Answer: 
Unit testing is validation and verification technology where the developer tests the individual units of source code. These individual units can be functions, methods or class.
Below is the simple Math class which has a Add function with two input parameter. The Add function basically adds the number and gives the addition of these two numbers.
As a developer we would like to test is this Add function actually works properly or not.
namespace TestVSTS
{
public class Math
   {
public int Add(int i, int j)
      {
         int sum;
         sum = i + j;
         return sum;
      }
   }
}
In order to do unit testing by using VSTS the first thing you need to create a simple unit test.In visual studio team system (VSTS) they provide the test menu in which you can select the unit testing as you can see in the below diagrams.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
 
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
 

After selecting unit test open the .cs file and write the logic in [TestMethod] attribute which you want to test.
[TestMethod]
public void Check()
     {
      Math obj = new Math();
      int r = obj.Calculate(10,20);
      Assert.AreEqual(30,r);
     }
Once you have completed the above steps, now set unit test project as startup project, and run the application.
If the function work properly it will gives us Passed result as you see in below diagram.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
If the Unit test gives us Failed result it means something wrong in function as you see in the below diagram.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
How will you do Unit Testing using Nunit?Answer:
Unit testing is validation and verification technology where the developer tests the individual units of source code. These individual units can be functions, methods or class.

Below is the simple Math class which has a Add function with two input parameter. The Add function basically adds the number and gives the addition of these two numbers.

As a developer we would like to test is this Add function actually works properly or not .
namespace NunitTest
{
    public class Math
    {
        public int Add(int i, int j)
        {
            int sum;
            sum = i + j;
            return sum;
        }
    }
}

In order to do unit testing by using Nunit the first thing you need to create a simple CheckNunit class as shown in the code below.
namespace CheckNunit
{
    [TestFixture]
    public class NunitTest
    {
        [Test]//it is called as attribute
        public void check()
        {
            Math obj = new Math();
            int result = obj.Add(10, 20);
            Assert.AreEqual(30, result);
        }
    }
}

In NunitTest class the check function is attributed by the Test.it is saying that we are passing 10 and 20 value and we are expecting the result as 30.if the result is 30 then everything is working properly else there is something wrong in the code.

Once you have completed the above steps, Open Nunit software and select the .dll file of CheckNunit like the following diagrams.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions
Now click on run button and see the respective output. If it displays green color then everything is working fine and if it displays red color then there is something wrong in code. The following two diagram will give you an better idea.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questionsLet inject a small defect, so that we can check how Nunit display the result. Now I change the Addition(+) sign as Multiplication(*) sign so the method fail to add values and Nunit displays Red signal like below diagram.
.NET Interview questions , C# Interview questions , ASP.NET Interview Questions , SQL Server interview questions

 

 Typical Complicated SQL query asked in .NET interviews to see if you know how to split columns into a row?

Answer: 
let's us assume that we have the following table of Employee.
Emp_IdEmp_NameEmp_Salary_2010Emp_Salary_2011
1
 
Shiv1700019000
2
 
Raju
 
1350015000
3
 
Sham1500018000
4
 
Moosa1100014000
5
 
Feroz1200016000
                     
Now we want to merge the Emp_Salary_2010 and Emp_Salary_2011 columns into a single column as Salary.
Query:-
select Emp_Name,Emp_Salary_2010 as Salary from Employee
union 
select Emp_Name,Emp_Salary_2011 as Salary from Employee
Output:-
 
Emp_NameSalary
Shiv17000
Shiv19000
Raju
 
13500
Raju
 
15000
Sham
 
15000
Sham
 
18000
Moosa
 
11000
Moosa
 
14000
Feroz12000
Feroz15000

 Typical Complicated SQL query asked in .NET interviews to test your SQL CASE syntax capability?
Answer: 
Let's us assume that we have the following table of Employee.
Emp_IdEmp_NameEmp_Salary
1Shiv17000
2Raju13500
3Sham15000
4Moosa11000
5Firoz12000
There can be a scenario we have to display employee name whose salary is greater than "some amount" or less than "some amount" for that purpose we use case statement.
Let's us consider that we have to display all the employee names from the employee table and the status like salary is greater than 13000 or lesser than 13000.
Query:
SELECT Emp_Name,CASE 
 when (Emp_Salary>13000) then 'Greater than 13000'
 else 'Lesser than 13000'
 end as Status
 FROM Employee
Output:
Emp_NameStatus
ShivGreater than 13000
RajuGreater than 13000
ShamGreater than 13000
MoosaLesser than 13000
FirozLesser than 13000
Hence you can see that all the employee name have been displayed with their salary status in the above output.

Select second highest salary from the table?
Answer: 
Let's us assume that we have the following table of Employee.

Emp_Id
 
Emp_Name
 
Emp_Salary
 
1
 
Shiv
 
17000
 
2
 
Raju
 
13500
 
3
 
Sham
 
15000
 
4
 
Moosa
 
11000
 
5
 
Feroz
 
12000
 
Now we want to find out second highest salary from Employee table, as you see that the second highest salary is 15000 and we want to display the same.

Query:-
SELECT Emp_Name,Emp_Salary
FROM Employee e1
WHERE
2 = (SELECT COUNT(DISTINCT (e2.Emp_Salary))FROM Employee e2 WHERE e2.Emp_Salary >= e1.Emp_Salary)
The above employee table contains two same records as second highest salary so the result set will look like below output table.

Output:-
Emp_NameEmp_Salary
Sham15000
        
If the table contains two or more same record of salary which is the second highest salary then the query will give you all the record of second highest salary as you see in the above output table.

21 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. I know you feel more happy when you get things done and best of all those things are your most precious treasure.
    python training in rajajinagar | Python training in btm | Python training in usa

    ReplyDelete
  3. Thanks for providing wonderful information with us. Thank you so much.
    Best Data Scientist Training in Chennai

    ReplyDelete
  4. Wonderful blog & good post. Its really helpful for me, awaiting for more new post. Keep Blogging!
    Python Training in Chennai | Python Training Institute in Chennai

    ReplyDelete
  5. Pretty! This info changed right into a in reality terrific post. Thank you for imparting the ones facts.

    ReplyDelete

  6. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.



    Machine Learning Training In Hyderabad

    ReplyDelete
  7. hank you for sharing this valuable and useful content, Being a premium Web Design Company In Surat, we are passionate about creating alluring mobile user interfaces that proudly represent your brands.keep to share all!!

    Android Training in Chennai

    Android Online Training in Chennai

    Android Training in Bangalore

    Android Training in Hyderabad

    Android Training in Coimbatore

    Android Training

    Android Online Training

    ReplyDelete
  8. You finished certain solid focuses there. I did a pursuit regarding the matter and discovered almost all people will concur with your blog.
    data science course delhi

    ReplyDelete
  9. Pretty! This was a really wonderful post. Thank you for providing these details.
    Technology

    ReplyDelete
  10. Fantastic blog extremely good well enjoyed with the incredible informative content which surely activates the learners to gain the enough knowledge. Which in turn makes the readers to explore themselves and involve deeply in to the subject. Wish you to dispatch the similar content successively in future as well.

    artificial intelligence course in raipur

    ReplyDelete
  11. Thanks for sharing the descriptive information. It’s hard to come by well-informed people in this particular topic, but you explained this really good.

    DevOps Training in Hyderabad

    ReplyDelete
  12. I am truly getting a charge out of perusing your elegantly composed articles. It would seem that you burn through a ton of energy and time on your blog. I have bookmarked it and I am anticipating perusing new articles. Keep doing awesome.
    data scientist training in hyderabad


    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete

Receive All Free Updates Via Facebook.