Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 在包含三列的表中搜索,其中搜索条件可能仅为一列、两列或三列?_Mysql_Sql_Database_Oracle - Fatal编程技术网

Mysql 在包含三列的表中搜索,其中搜索条件可能仅为一列、两列或三列?

Mysql 在包含三列的表中搜索,其中搜索条件可能仅为一列、两列或三列?,mysql,sql,database,oracle,Mysql,Sql,Database,Oracle,我有一个数据库表包含电子邮件,代码,名称。我有一个查看搜索页面,可以只接收电子邮件作为输入,也可以只接收代码或名称或电子邮件和名称或电子邮件和代码或电子邮件,名称,代码或什么都没有。因此,无论搜索条件是什么,我都需要从数据库返回相关行。如何管理我的查询?有什么建议吗?有什么最佳实践吗 注意:实际上我有三个表,从那里我通过连接查询得到这些数据 谢谢。典型的方法是: where (? is null or email = ?) and (? is null or code = ?) an

我有一个数据库表包含电子邮件,代码,名称。我有一个查看搜索页面,可以只接收电子邮件作为输入,也可以只接收代码或名称或电子邮件和名称或电子邮件和代码或电子邮件,名称,代码或什么都没有。因此,无论搜索条件是什么,我都需要从数据库返回相关行。如何管理我的查询?有什么建议吗?有什么最佳实践吗

注意:实际上我有三个表,从那里我通过连接查询得到这些数据

谢谢。

典型的方法是:

where (? is null or email = ?) and
      (? is null or code = ?) and
      (? is null or name = ?)
这需要将每个参数传递两次。因此,这是使用命名参数的一个很好的理由:

where (:email is null or email = :email) and
      (:code is null or code = :code) and
      (:name is null or name = :name)

谢谢你的回复。我想说得更清楚一点。假设我用'forhad@mail.com'. 然后,查询将类似于(请在这一点上让我澄清)-where('forhad@mail.com'为空或为空forhad@mail.com“)和(?为null或代码=?)和(?为null或名称=?)?Thanks@forhadmethun . . . 基本上,除了假定的
将用
NULL
填充,因为这些参数没有值。