我正在具有表productDetails 的数据库中进行搜索。
我想要在 Sequelize 中进行类似的查询,
SELECT * FROM productDetails
WHERE title
LIKE '%search1%' OR title
LIKE '%search2%'
当前使用
const pd= await ProductDetail.findAll({
where: {
[Op.or]: {
title: { [Op.like]: `%search1%` },
title: { [Op.like]: `%search2%` },
},
},
最佳答案
只需将所有条件指示为数组作为 Op.or
的值,如下所示:
where: {
[Op.or]: [
{ title: { [Op.like]: `%search1%` } },
{ title: { [Op.like]: `%search2%` } },
],
},
查看示例 here
关于mysql - 在同一列中进行多次搜索 MySQL Sequelize,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71235342/