Open In App

SQL Query to Select all Records From Employee Table Where Name is Not Specified

Last Updated : 14 May, 2021
Like Article

Here, we are going to see how to find the names of the persons other than a person with a particular name  SQL. In this article, we will be making use of the MSSQL Server as our database.

For example, if the employee name is Pradeep you need to show the table of employees excluding that employee with the name Pradeep. So let us execute this query in detail step-by-step.

Creating a database :

Creating a database employee by using the following SQL query as follows.


Output :

Using the database :

Using the database employee using the following SQL query as follows.

USE employee;

Output :

Creating a table :

Creating a table employee_details with  4 columns using the following SQL query as follows.

  CREATE TABLE employee_details(
     emp_id VARCHAR(8),
     emp_name VARCHAR(20),
     emp_designation VARCHAR(20),
     emp_age INT);

Output :

Verifying the table:

To view the description of the tables in the database using the following SQL query as follows.

EXEC sp_columns employee_details;

Output :

Inserting data into the table :

Inserting rows into employee_details table using the following SQL query as follows.

INSERT INTO employee_details VALUES('E40001','PRADEEP','H.R',36),
    ('E40003','PAVAN KUMAR','ASST MANAGER',28),
    ('E40004','SANTHOSH','STORE MANAGER',25),
    ('E40005','THAMAN','GENERAL MANAGER',26);

Output :

Verifying the inserted data :

Viewing the table employee_details after inserting rows by using the following SQL query as follows.

SELECT * FROM employee_details;

Output :

  • Query to find an employee whose name is not Pradeep.

Since we need to display the names other than Pradeep we can use not equal to (<>) operator with the where clause to get the required query executed, In the WHERE clause we can use any other conditions also using other operators such as >,<, AND, OR, NOT etc..,

FROM table_name
WHERE condition1 ,condition 2,....;

For the above we can do it in two ways:

1) USING <> operator

 SELECT* FROM employee_details
 WHERE emp_name <>'PRADEEP';

Output :

2) USING NOT operator

  SELECT* FROM employee_details
  WHERE NOT emp_name='PRADEEP';

Output :

  • Query to find the employee whose designation is not of General Manager and Store Manager.

Using AND operator we can merge different conditions here AND is used to execute the following query.

  SELECT* FROM employee_details
  WHERE  emp_designation<> 'GENERAL MANAGER' AND
  emp_designation <> 'STORE MANAGER';

Output :

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads