228k views
2 votes
What is the result of the following SQL query?

SELECT lname FROM hourly
INTERSECT
SELECT lname FROM salaried;

User Junsu Cho
by
8.7k points

1 Answer

4 votes

Final answer:

The result of the given SQL query is the common values in the 'lname' column between the 'hourly' and 'salaried' tables.

Step-by-step explanation:

The SQL query provided selects the 'lname' column from two tables, 'hourly' and 'salaried', and returns the common values in both tables. This operation is called the 'INTERSECT' operator in SQL.

For example, if the 'lname' column in the 'hourly' table contains the values ['Smith', 'Johnson', 'Williams'] and the 'lname' column in the 'salaried' table contains the values ['Johnson', 'Williams', 'Brown'], the result of the query would be ['Johnson', 'Williams'] since those are the common values found in both tables.

Therefore, the result of the SQL query SELECT lname FROM hourly INTERSECT SELECT lname FROM salaried would be the common values in the 'lname' column between the 'hourly' and 'salaried' tables.

The SQL query will return all last names (lname) that are present in both the hourly and salaried tables. The INTERSECT operator is used to combine two SELECT statements and returns only those records that are common to both SELECT statements.

For example, if the hourly table contains last names Smith, Johnson, and Williams, and the salaried table contains last names Johnson, Williams, and Brown, the result of this query will be the last names Johnson and Williams as these are the only two last names present in both tables.

User Joshua Kaden
by
7.8k points