Saturday 15 May 2010

sql - mysql get second possible value when first one is not available -



sql - mysql get second possible value when first one is not available -

in application, have list of freelancers in table , working rates configuration in table. working rates configuration per hr rate, per day rate, per work type rate

some freelancers not have per hr rate, instead per day or per work type.

my initial query (left outer) joining freelancer table freelancer_workrates table , filtering rows based on perhrrate. whenever perhrrate not available, retrieve next available rate using same query. possible?

currently, checking in resultset , making separate phone call freelancers next available rate. ends in making many sql queries database. avoid situation.

are there suggestions?

use coalesce

this pick first non null value out of 3 rates

coalesce(perhrrate, perdayrate, perworktyperate)

mysql sql subquery

No comments:

Post a Comment