mysql只选择php中不为null的数据

s5a0g9ez  于 2021-06-17  发布在  Mysql
关注(0)|答案(2)|浏览(407)

**结束。**此问题需要详细的调试信息。它目前不接受答案。
**想改进这个问题吗?**更新问题,使其成为堆栈溢出的主题。

11个月前关门了。
改进这个问题
我对获取有问题 null 我数据库里的数据。每次我运行查询时 null 存储为 null 在我的数据库表中。如果表列 null 值,那么我不想选择它。
我已经尝试过此查询:

  1. $sql= mysqli_query(
  2. $connect,
  3. "SELECT col_1,col_2 FROM table where col_1 = 'value' or col_2 = '' "
  4. ) die(mysqli_error($connect));

如果值为 nullcol_2 那我想避免…但我不知道怎么解决这个问题。

hmtdttj4

hmtdttj41#

  1. $sql= mysqli_query($connect,"SELECT col_1,col_2 FROM table where col_1 = 'value' or col_2 IS NOT NULL ");
jfewjypa

jfewjypa2#

where col_1 = 'value' or col_2 = '' 事实上,这个 OR 表达式允许 null 中的值 col2 ,只要 col_1 等于 'value' .
你想要:

  1. where col_2 is not null and (col_1 = 'value' or col_2 = '')

相关问题