使用UNIONS的MySQL / MySQLi SELECT没有NULLS和ORDERED BY如何?

时间:2018-02-03 22:36:53

标签: php mysql mysqli

我有这个......

$query = "SELECT {$selections} FROM {$table_1} 
        UNION ALL SELECT {$selections} FROM {$table_2} 
        UNION SELECT {$selections} FROM {$table_3}
        UNION SELECT {$selections} FROM {$table_4}
        ORDER BY FIELD(series, {$seriesOrder}) ";

这很好用,但我现在要做的是排除{$ column_7}中每个表都有NULL值的值,我试过了....

$query = "SELECT {$selections} FROM {$table_1} WHERE {$column_7} IS NOT NULL
        UNION ALL SELECT {$selections} FROM {$table_2} WHERE {$column_7} IS NOT NULL
        UNION SELECT {$selections} FROM {$table_3} WHERE {$column_7} IS NOT NULL
        UNION SELECT {$selections} FROM {$table_4} WHERE {$column_7} IS NOT NULL
        ORDER BY FIELD(series, {$seriesOrder})";

然而,这不起作用! 我显然遗漏了一些东西,一直在研究这个问题,找不到答案需要帮助,请...

1 个答案:

答案 0 :(得分:-1)

这是通过纠正标点符号/语法错误来解决的,这是一个缺少撇号的错误! 哇!! : - )