1 | initial version |
Yes, you can choose the values from a row depending on whether another row is distinct using a subquery. Here is an example:
Suppose you have a table called "employee" with columns "name", "salary", and "department". You want to select the salary of all employees in departments where there is at least one employee with a salary greater than $100,000.
You can achieve this using the following query:
SELECT salary
FROM employee
WHERE department IN (
SELECT DISTINCT department
FROM employee
WHERE salary > 100000
)
The subquery selects the distinct departments where there is at least one employee with a salary greater than $100,000. The outer query then selects the salary of all employees in those departments.