📅  最后修改于: 2022-03-11 15:05:12.739000             🧑  作者: Mango
SELECT
users_first_name,
users_last_name
FROM
(
(
SELECT
users.first_name AS users_first_name,
users.last_name AS users_last_name
FROM
users
INNER JOIN companies ON companies.id = users.company_id
WHERE
(
users.last_name LIKE 'TERM%'
)
)
UNION
DISTINCT (
SELECT
users.first_name AS users_first_name,
users.last_name AS users_last_name
FROM
users
INNER JOIN companies ON companies.id = users.company_id
WHERE
(users.first_name LIKE 'TERM%')
)
UNION
DISTINCT (
SELECT
users.first_name AS users_first_name,
users.last_name AS users_last_name
FROM
users
INNER JOIN companies ON companies.id = users.company_id
WHERE
(companies.name LIKE 'TERM%')
)
) AS union1;