MySQL Поиск нескольких таблиц
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;
steamboatid