Skip to content
Advertisement

Is there a better way to write this SQL query? (UNION)

I tried using OR in the WHERE clause for this code but I get an error on the TIMESTAMP_FORMAT function, but this as such can’t be the issue because it’s exactly the same as in the working code when using UNION.

When I use a UNION in the code it works perfectly and I get exactly what I want, but I seriously doubt that’s the correct way to do it.

I want all records that have text starting with (PUP) on field UPTEXT which DO NOT have an empty value on field UPLSTD AND that have a LAST USED date that’s older than 12 days on field UPLSTD I don’t want the empty ones here because I can’t use the TIMESTAMP_FORMAT function on empty values. But what I also need is all records that also have text starting with (PUP) on field UPTEXT but do have an empty value on field UPLSTD AND that have a CREATION date that’s older than 12 days on field UPCRTD.

This is the faulty code:

This is the working code:

Advertisement

Answer

Make two steps:

like this:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement