简体   繁体   English

mysql SELECT WHERE仅特定列具有值

[英]mysql SELECT WHERE only specific columns have values

Good day 美好的一天

I have a table with a dozen columns and i'm looking for a query that will return rows that only have specific columns filled up. 我有一个带有十几列的表,我正在寻找一个查询,该查询将返回仅填充特定列的行。 So it shouldn't return rows where 'illegal' columns are filled up. 因此,它不应返回填充“非法”列的行。

Something like: 就像是:

SELECT * FROM table WHERE col1 is NOT NULL 
AND all_other_cols is NULL;

^ i know it can be done by listing every other column and indicating "not NULL", but is there another way of doing this? ^我知道可以通过列出其他所有列并指出“ not NULL”来完成此操作,但是还有另一种方法吗?

Hopefully this makes sense 希望这有道理

UPDATE: 更新:

Based on the answers below I'll just use "DESCRIBE my_table;" 根据以下答案,我将仅使用“ DESCRIBE my_table;”。 then build a query that will filter all unwanted columns with 'is NULL' 然后建立一个查询,以“ is NULL”过滤所有不需要的列

There is no direct feature for that. 没有直接的功能。 But what you can do is this: 但是,您可以执行以下操作:

You concatenate all table columns to a single string and then test that string against the column that is not meant to be NULL . 您将所有表列连接为单个字符串,然后针对该字符串( 不是 NULL These two values can only be identical if all other columns are empty or hold NULL . 仅当所有其他列为空或保持NULL这两个值才能相同。

The answer to this question might help with how to even simplify that: 该问题的答案可能有助于简化操作:

MySQL concatenating all columns MySQL连接所有列

我认为您的方法是最简单的方法

您可以使用ISNULL条件: 在此处签出

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM