![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I have 3 tables all with the data field (field1). I want to extract a recordset with distinct values from these tables BUT I do not want null or blanks to appear in the recordset. The following is what I am using (failing with). SELECT DISTINCT field1 FROM DB1 UNION SELECT DISTINCT field1 FROM DB2 UNION SELECT DISTINCT field1 FROM DB3 WHERE field1 != "(null)" AND field1 ! ="" If I drop the WHERE clause, the select works but, of course, I get nulls.l |
#3
| |||
| |||
|
|
On 2011-01-14 22:09, bruce wrote: I have 3 tables all with the data field (field1). I want to extract a recordset with distinct values from these tables BUT I do not want null or blanks to appear in the recordset. The following is what I am using (failing with). SELECT DISTINCT field1 FROM DB1 UNION SELECT DISTINCT field1 FROM DB2 UNION SELECT DISTINCT field1 FROM DB3 WHERE field1 != "(null)" AND field1 ! ="" If I drop the WHERE clause, the select works but, of course, I get nulls.l I'm not clear on whether you want to avoid null or '(null)' but I'll assume null. Null equals nothing, not even null so you cannot use for example = to test for null. There is a special predicate IS [NOT] NULL that can be used to compare against null: SELECT DISTINCT field1 FROM DB3 WHERE field1 IS NOT NULL * AND field1 !="" FYI, != is not standard even though many dbms accepts it, you can use instead. Also ' is the standard string delimiter, and finally union will itself remove duplicates, so there is no point in using distinct: SELECT field1 FROM DB1 UNION SELECT field1 FROM DB2 UNION SELECT field1 FROM DB3 WHERE field1 IS NOT NULL * AND field1 <> '' or SELECT field1 FROM DB1 UNION SELECT field1 FROM DB2 UNION SELECT field1 FROM DB3 WHERE coalesce(field1, '') <> '' /Lennart |
![]() |
| Thread Tools | |
| Display Modes | |
| |