D
D
Danil2016-07-13 17:20:33
MySQL
Danil, 2016-07-13 17:20:33

How to correctly form a query to mysql?

There is an array of View IDs [123321, 154874, 12233] and so on.
There is a basis in which these ID are written down. How can I make a request to the database so that only those IDs that are not in the database are returned to me?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Fedorov, 2016-07-13
@qonand

SELECT * FROM tablename WHERE id NOT IN (123321, 154874, 12233)

E
Evgeny Bezymyannikov, 2016-07-13
@psman

Select * From xxx Where xxx.id NOT IN (123321, 154874, 12233);
At a large number of records there will be brakes still those.

M
Melkij, 2016-07-13
@melkij

MySQL? Uncomfortable.

select /**/ from (
    select 123321 as id
    union all
    select 154874
    union all
    select 12233
) as targets
where not exists (
    select 1 from tablename where tablename.id = targets.id
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question