Mysql 条件查询时记录的唯一id,有多个id并且已知的,该怎么查询

已知id的值,比如
int pId[100];

CString sql;
sql.Format("select * from table_name where id!=%d and id!=%d and id!=%d .....",pId[0],pId[1],pId[2],.....);
难道是这样写吗?

用not in试试,这么写;

select * from table_name where id not in (1,2,3,4,5,...)

select * from table_name where id in(1,2,3);

如果id很多,建议,把id单独拼接到一个表里,然后直接:

select * from table_name where id not in (select id from temp)
或者
select * from table_name t where not exists (select 1 from temp where t.id = temp.id )