You listed several databases and no specific version… In any case, you will need to generate appropriate SELECT
s - either in Excel as suggested by Lalit Kumar B, using some text processor, or even (partly) in your database.
For MySQL, you'd work towards the statements to be used in the subselect resulting in "T".
SELECT T.firstName, T.lastName FROM
(SELECT 'Afirst' firstName, 'Alast' lastName UNION ALL
SELECT 'Dfirst' firstName, 'Dlast') T
LEFT JOIN Users U
ON U.firstName = T.firstName
AND U.lastName = T.lastName
WHERE U.firstName IS NULL AND U.lastName IS NULL;
SQL Fiddle
In Oracle you use DUAL
to construct the statements:
SELECT T.firstName, T.lastName FROM
(SELECT 'Afirst' firstName, 'Alast' lastName FROM DUAL UNION ALL
SELECT 'Dfirst' firstName, 'Dlast' FROM DUAL) T
LEFT JOIN Users U
ON U.firstName = T.firstName
AND U.lastName = T.lastName
WHERE U.firstName IS NULL AND U.lastName IS NULL
;
and in more recent versions, you have the option to factor:
WITH
T (firstName, lastName) AS (
SELECT 'Afirst' firstName, 'Alast' lastName FROM DUAL UNION ALL
SELECT 'Dfirst' firstName, 'Dlast' FROM DUAL
)
SELECT T.firstName, T.lastName
FROM T
LEFT JOIN Users U
ON U.firstName = T.firstName
AND U.lastName = T.lastName
WHERE U.firstName IS NULL AND U.lastName IS NULL
;
which would even allow to split the columns in the database (If you have more than two or three columns in your Excel to compare with the Users table, you'd probably use one of the more elaborate CSV splitting approaches - if your Oracle version permits.):
WITH
T (string) AS (
SELECT 'Afirst,Alast' FROM DUAL UNION ALL
SELECT 'Dfirst,Dlast' FROM DUAL
),
TUser (firstName, lastName) AS (
SELECT
SUBSTR(string, 1, INSTR(string, ',') - 1)
, SUBSTR(string, INSTR(string, ',') + 1, LENGTH(string))
FROM T
)
SELECT T.firstName, T.lastName
FROM TUser T
LEFT JOIN Users U
ON U.firstName = T.firstName
AND U.lastName = T.lastName
WHERE U.firstName IS NULL AND U.lastName IS NULL
;
SQL Fiddle
And if some database is not as relaxed as MySQL (requiring no table in the SELECT
), and has no equivalent for Oracle's "DUAL", you can still create such a one column / one row table and proceed.
Please comment, if and as adjustment / further detail is required.