Page is a not externally linkable
- Code, Content, and Presentation
-- Databases
---- replacement value for when left join condition is not met.


nelsonm - 6:50 am on Sep 16, 2011 (gmt 0)


hi all,

other than testing a result field value with an if statement, does mysql offer the ability to set a replacement value in a left join when the condition is not met?

For instance...

SELECT customer.name
FROM workorder
LEFT JOIN customer
ON workorder.id = customer.id ELSE USE 'Not Defined'


So the idea is if there's no matching customer.id, assign 'Not Defined' to customer.name instead of executing the following...

$customer = mysql_fetch_array($result,MYSQL_NUM);

if($customer['name'] == '') $customer['name'] = 'Not Assigned';


thanks.


Thread source:: http://www.webmasterworld.com/databases_sql_mysql/4363223.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com