How do I conditionally select a field from one of two tables?
Posted
by freakwincy
on Stack Overflow
See other posts from Stack Overflow
or by freakwincy
Published on 2010-04-15T14:10:19Z
Indexed on
2010/04/15
14:13 UTC
Read the original article
Hit count: 198
I have two tables invoices and pending_payments both of which have the following rows in common: invoice_id and balance. I want to do a select in MySQL that'll work thus:
[pseudo-code]
if(invoice_id exists in pending_payments table) {
select balance from pending_payments where invoice_id = yadayadayada
} else {
select balance from invoices where invoice_id = yadayadayada
}
Is this even doable in MySQL? If so, how?
© Stack Overflow or respective owner