Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个值数组,我想检查它是否已经在数据库中。这个数组可以增长到 100 个元素。检查它的最佳方法是什么?我应该提取所有表数据然后检查它吗?应该/我可以在 1 个 SQL 语句中执行此操作吗?如果是这样,怎么做?我正在使用 PHP。
编辑:
我应该补充一点,我正在检查数据库中有哪些,然后我可以添加那些不在数据库中的。也许有比我想的更好的解决方案。
我假设 PHP
$sql = "SELECT name FROM tablename WHERE name IN ('".implode("','", $array_of_names)."')";
像这样动态创建一个语句:
select * from table where value in (3, 5, 8, 12, 17, (etc))
以您使用的任何语言从数组中生成值列表。