laosace
laosace

Reputation: 1

Query for a row where the same value is shared across columns

I have a table:

The Alias is unique.

Scenario: an employee needs to get his/her account reactivated. To do this they must go through a process of verification.

The table will then place an alias number into each column ( manager, auditor, activator) of whomever does the request. By rule employee cannot use his or herself to activate their own account.

How can i write a query to list all rows and columns displaying an employee having their alias showing up under manager and auditor, or manager and activator? ( in other words they are breaking the rules and verifying themselves)

Upvotes: 0

Views: 38

Answers (2)

CurseStacker
CurseStacker

Reputation: 1079

From your statement

alias showing up under manager and auditor, or manager and activator

SELECT alias, manager, auditor, activator
FROM Employees
WHERE (manager = alias AND auditor = alias) OR (manager = alias AND activator = alias)

Upvotes: 0

bbrumm
bbrumm

Reputation: 1352

Is the rule you're looking for that the alias needs to be different to the manager, auditor and activator values?

If so, could you try a query like this?

SELECT alias, manager, auditor, activator
FROM employees
WHERE alias = manager
OR alias = auditor
OR alias = activator;

Upvotes: 0

Related Questions