Select only rows with at least 2 non-missing values
I have the following way to get the IDs of the rows that have at least two not null values; however, I am afraid this is not efficient when it comes to few million rows per table. I'd like to share it anyway:

mysql&gt; select * from l;
+------+------+------+------+------+------+------+------+
| id   | var1 | var2 | var3 | var4 | var5 | var6 | var7 |
+------+------+------+------+------+------+------+------+
|    1 | NULL |    4 |    9 | NULL | NULL | NULL |    7 |
|    2 | NULL | NULL | NULL | NULL | NULL |    1 |    2 |
|    3 |    4 |    5 |   23 |    1 |    2 |    4 |   22 |
+------+------+------+------+------+------+------+------+
3 rows in set (0.00 sec)

mysql&gt; select id, 5-(isnull(var1)+isnull(var2)+isnull(var3)+isnull(var4)+isnull(var5)) AS non_null_count from l;
+------+----------------+
| id   | non_null_count |
+------+----------------+
|    1 |              2 |
|    2 |              0 |
|    3 |              5 |
+------+----------------+
3 rows in set (0.00 sec)

mysql&gt; SELECT id FROM (select id, 5-(isnull(var1)+isnull(var2)+isnull(var3)+isnull(var4)+isnull(var5)) AS non_null_count from l)x WHERE non_null_count&gt;=2;
+------+
| id   |
+------+
|    1 |
|    3 |
+------+
2 rows in set (0.01 sec)


Basically, I am "counting" how many non-null values exist in each row.