Or you can use code similar to the below without resorting to DButils::
B4X:
Dim DBFilePath As String = File.DirRootExternal
Dim MyTextWriter As TextWriter
Dim MyList As List
Dim MyCode As String
Dim txt As String
MyList.Initialize
MyTextWriter.Initialize(File.openoutput(DBFilePath,"Chems.csv",False))
txt = "SELECT * FROM tblChemicals"
Cursor1 = SQL1.ExecQuery(txt)
For i=0 To Cursor1.RowCount-1
Cursor1.Position=i
Mycode =Cursor1.GetString("CODE") & "," & Cursor1.GetString("CHEMICAL") 'comma delimnited text File
MyList.Add(Mycode)
Next
MyTextWriter.WriteList(Mylist)
MyTextWriter.close
You should use StringUtils.SaveCSV to create a csv file. The above code will create a corrupted CSV file is there is a comma or quote in one of the fields.
JOIN (INNER, LEFT, etc) are clauses of SQL SELECT, and SQL commands are sent by B4A, not run (this is the work of the DBMS).
If you're used to LINQ for example, just forget. You have to compose the SQL query as a string ("SELECT * FROM Table1 INNER JOIN Table2 ON...").