I am trying to assign a value returned by a MySQL query to a variable in R, or 0 in case the query returns empty set (no records found). I thought I could use COALESCE like this:
data<-dbGetQuery(con,"COALESCE(( SELECT id FROM payments WHERE user_id=25578),0)")
However, I get a syntax error message:
RS-DBI driver: (could not run statement: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM payments WHERE user_id=25578,0)' at line 1).
I have been trying to find an alternative but unsuccessful. Thanks for help!
If data is available for the particular id ‘1’ will be displayed otherwise ‘0’ will be displayed.