2013/2/6 JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>:
> I have an UPDATE query with the following general structure:
>
> UPDATE table1 SET (SELECT field FROM table2 WHERE conditions ORDER BY
> order_field LIMIT 1)
>
> Is it possible to assign a default value in case no results are returned by
> the SELECT statement?
One option would be to do something with UNION along these lines:
UPDATE table1 SET field =
(SELECT field FROM table2 WHERE conditions
UNION
SELECT 'default_value' WHERE NOT EXISTS (SELECT field FROM table2
WHERE conditions )
ORDER BY order_field LIMIT 1
)
HTH
Ian Barwick