È necessario utilizzare una condizione OR / AND:
SELECT TOP (1)
employee_id, employee_ident, utc_dt, rx_dt
FROM employee
INNER JOIN employee_mdata_history
ON employee.ident = employee_mdata_history.employee_ident
WHERE employee_id like 'emp1%'
OR employee_id like 'emp3%'
ORDER BY rx_dt desc;
Dai un'occhiata a OR (Transact-SQL) su MS-Docs.
Ho creato un esempio:
create table employees(employee_id varchar(10), employee_name varchar(100));
insert into employees values
('emp10', 'Bryan Nelson'),
('emp12', 'Rosalyn Sanders'),
('emp13', 'Rose Tudler'),
('emp20', 'Julio Gomez'),
('emp30', 'Ian McGregor'),
('emp40', 'Anne Hatt');
GO
SELECT employee_id, employee_name
FROM employees
WHERE employee_id LIKE 'emp1%'
OR employee_id LIKE 'emp3%';
GO
employee_id | Nome dipendente
: ---------- | : --------------
emp10 | Bryan Nelson
emp12 | Rosalyn Sanders
emp13 | Rose Tudler
emp30 | Ian McGregor
Tieni presente che stai utilizzando TOP 1, otterrai una riga massima, indipendentemente da quante condizioni utilizzi.
SELECT TOP 1 employee_id, employee_name
FROM employees
WHERE employee_id LIKE 'emp1%'
OR employee_id LIKE 'emp3%';
GO
employee_id | Nome dipendente
: ---------- | : ------------
emp10 | Bryan Nelson
Se sono necessarie le righe TOP (X) WHERE employee_id LIKE 'emp1%'
più le righe TOP (X), WHERE employee_id LIKE 'emp3%'
è possibile utilizzare due istruzioni select unite con UNION ALL.
SELECT TOP 3 employee_id, employee_name
FROM employees
WHERE employee_id LIKE 'emp1%'
UNION ALL
SELECT TOP 1 employee_id, employee_name
FROM employees
WHERE employee_id LIKE 'emp3%'
GO
employee_id | Nome dipendente
: ---------- | : --------------
emp10 | Bryan Nelson
emp12 | Rosalyn Sanders
emp13 | Rose Tudler
emp30 | Ian McGregor
Inoltre aggiungerò una ricerca di pattern, ma questa soluzione restituisce tutti i record che corrispondono al pattern: LIKE 'emp [13]%'
SELECT employee_id, employee_name
FROM employees
WHERE employee_id LIKE 'emp[13]%'
GO
employee_id | Nome dipendente
: ---------- | : --------------
emp10 | Bryan Nelson
emp12 | Rosalyn Sanders
emp13 | Rose Tudler
emp30 | Ian McGregor
dbfiddle qui