SQL Select between two fields depending on the value of one field

Posted by Filip on Stack Overflow See other posts from Stack Overflow or by Filip
Published on 2010-05-26T11:20:53Z Indexed on 2010/05/26 13:51 UTC
Read the original article Hit count: 171

Filed under:
|
|

Hi. I am using a PostgreSQL database, and in a table representing some measurements I've two columns: measurement, and interpolated. In the first I've the observation (measurement), and b is the interpolated value depending on nearby values. Every record with an original value has also an interpolated value. However, there are a lot of records without "original" observations (NULL), hence the values are interpolated and stored in the second column. So basically there are just two cases in the database:

Value  Value  
NULL   Value

Of course, it is preferable to use the value from the first column if available, hence I need to build a query to select the data from the first column, and if not available (NULL), then the database returns the value from the second column for the record in question. I have no idea how to build the SQL query.

Please help. Thanks.

© Stack Overflow or respective owner

Related posts about sql

Related posts about postgresql