176k views
2 votes
What query would we use to select all the employees from the Employees table whose first name is the same as his last name?

SELECT* FROM Employee WHERE (firstName = firstName) AND (lastName = lastName)
SELECT* FROM Employee WHERE firstName = last NAME
SELECT FROM Employee JOIN Employee ON firstName = lastName
Select DISTINCT firstName, lastName FROM Employee

User Navin Leon
by
7.4k points

1 Answer

5 votes

Answer:

SELECT* FROM Employee WHERE firstName = lastName;

Step-by-step explanation:

The first query you provided:

SELECT* FROM Employee WHERE (firstName = firstName) AND (lastName = lastName)

is not correct, because it's comparing the firstName column to itself, and the lastName column to itself, so it will always return true, and will return all the rows in the Employee table regardless of the firstName or lastName values.The second query:

SELECT* FROM Employee WHERE firstName = last NAME

is better, but it's not correct because it has a typo, it should be

SELECT* FROM Employee WHERE firstName = lastName

This query is checking if the firstName column is equal to the lastName column, and if so it will return the entire row of that employee.The third query:

SELECT FROM Employee JOIN Employee ON firstName = lastName

is not correct because it's trying to join the Employee table to itself, which is unnecessary and will not return the correct results. Also, it is missing the '*' after the SELECT statement.The fourth query:

Select DISTINCT firstName, lastName FROM Employee

is not correct because it is only returning the firstName and lastName columns and not the entire row. Also, it is using the DISTINCT keyword which will remove any duplicate rows, but since firstName and lastName should be unique for each employee, it's not necessary here.The correct query should be

SELECT * FROM Employee WHERE firstName = lastName;

This query will return all columns from the Employee table, where the firstName is equal to the lastName.

User MindSpiker
by
8.5k points