I'm trying to figure out how these statements really work, and am having some trouble with the documentation (and the software!).
Using the example publishers database (Mathematica 8), the following works fine (as documented):
SQLSelect[conn,{"TITLES","ROYSCHED"},{{"TITLES","TITLE"},
{"TITLES","TITLE_ID"},{"ROYSCHED","TITLE_ID"},{"ROYSCHED","ROYALTY"}},
"MaxRows"->5]
Now, there is no column ROYALTY in the TITLES table, so perhaps I should be able to write
SQLSelect[conn,{"TITLES","ROYSCHED"},{{"TITLES","TITLE"},
{"TITLES","TITLE_ID"},{"ROYSCHED","TITLE_ID"},"ROYALTY"},
"MaxRows"->5]
But this results in the error
DatabaseLink`SQL`Private`SQLValue::illegalvalue:
The value {{TITLES,TITLE},{TITLES,TITLE_ID},{ROYSCHED,TITLE_ID},ROYALTY}
cannot be converted to a value in an SQL statement.
So apparently either none or all of the entries in the columns list must themselves be lists. Is this right, or a bug, or what?
So assuming that this is correct, and all the columns must be lists in any multi-table inner join, how can I then apply a function such as COALESCE to the results to cast NULLs to zero? I tried {"TITLES","COALESCE(TITLE_ID,0) AS TITLE_ID"}, which failed because the string passed to the JDBC driver was TITLES.COALESCE(TITLE_ID,0) AS TITLE_ID, which is of course incorrect.
At the risk of asking too many questions in one question, let me add: I'm perfectly OK with simply returning the rows I want, with whatever NULLs may be in them. But can someone tell me the right way to turn all those NULLs to zeros once the result set is a Mathematica list?
SQLExecute. To replace NULL, simply dolist /. Null->0. – C. E. Aug 04 '13 at 09:52SQLSELECT[conn,{"TITLES","ROYSCHED"},{"TITLE","ROYALTY"}]works just fine --- andTITLEis a column only inTITLES,ROYALTYonly inROYSCHED. – rogerl Aug 05 '13 at 00:23