﻿ SQL: Find those employees whose last name is Dosni or Mardy

# SQL Exercise: Find those employees whose last name is Dosni or Mardy

## SQL Boolean Operator Statement: Exercise-11 with Solution.

From the following table, write a SQL query to find the details of all employees whose last name is ‘Dosni’ or ‘Mardy’. Return emp_idno, emp_fname, emp_lname, and emp_dept.

Sample table : emp_details

``` EMP_IDNO EMP_FNAME       EMP_LNAME         EMP_DEPT
--------- --------------- --------------- ----------
127323 Michale         Robbin                  57
526689 Carlos          Snares                  63
843795 Enric           Dosio                   57
328717 Jhon            Snares                  63
444527 Joseph          Dosni                   47
659831 Zanifer         Emily                   47
847674 Kuleswar        Sitaraman               57
748681 Henrey          Gabriel                 47
555935 Alex            Manuel                  57
539569 George          Mardy                   27
733843 Mario           Saule                   63
631548 Alan            Snappy                  27
839139 Maria           Foster                  57
```

Sample Solution :

``````-- This query selects all columns from the 'emp_details' table.
SELECT *
-- Specifies the table from which to retrieve the data (in this case, 'emp_details').
FROM emp_details
-- Filters the rows to only include those where the 'emp_lname' column has the value 'Dosni' or 'Mardy'.
WHERE emp_lname = 'Dosni' OR emp_lname = 'Mardy';
``````

Output of the Query:

```emp_idno	emp_fname	emp_lname	emp_dept
444527		Joseph		Dosni		47
539569		George		Mardy		27
```

Code Explanation:

The SQL query that is selecting all columns (*) from the 'emp_details' table where the value of the "emp_lname" column is equal to 'Dosni' OR the value of the "emp_lname" column is equal to 'Mardy'.
In this query, all rows that meet either of these criteria in the 'emp_details' table will be returned.
This will return a list of all the rows where the employee's last name is 'Dosni' or 'Mardy' or both.

Relational Algebra Expression:

Relational Algebra Tree:

## Query Visualization:

Duration:

Rows:

Cost:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous SQL Exercise: Using precedence with specified condition.
Next SQL Exercise: Employees that work in department 47 or department 63.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

﻿