![]() |
| |||
| I need to solve a problem similar to the language one whereby if a translation in the chosen languange does not exist, the default one should be selected. My problem is actually picking a price specific to a certain class if available or a default price otherwise. So taking a table like: classitemprice A50 1A60 B30 C20 2C0 to find the price of item A I could do: SELECT `price` FROM `price_table` WHERE `item` = '$item' AND (`class` = '$class' OR `class` = '') ORDER BY `class` DESC LIMIT 1 so if $item was 'A' $class was '1', I would get 60, otherwise I will get 50. Or I could do SELECT COALESCE(`s`.`price`,`d`.`price`) `price` FROM `price_table` `d` LEFT JOIN `price_table` `s` ON `s`.`item` = `d`.`item` AND `s`.`class` = '$class' WHERE `d`.`item` = '$item' AND `d`.`class` = '' My inclination is to go with the LEFT JOIN, but what do others think? |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |