''.', <column alias name>, <compound operator>, AS, BETWEEN, FROM, GROUP, IN, LIMIT, ORDER, WHERE, comma or semicolon expected, got 'SELECT'
Please I need help fixing the error above _ in the title _ appeared in the first SELECT after FROM of this query, all suggestions are welcome so thank you very much.
public ArrayList<HashMap<String, String>> getAll_Datas() {
ArrayList<HashMap<String, String>> arrayListAllData = new
ArrayList<HashMap<String, String>>();
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.rawQuery
(
" SELECT lespontes.idPontes ,\n" +
" lespontes.Cage as Cage,\n" +
" lespontes.Couvés,\n" +
" dbfécondation.Fécondés " + "FROM " +
(
" SELECT idPontes FROM lespontes"+
" UNION "
+ " SELECT idPontes FROM dbfécondation" ) +
" LEFT OUTER JOIN"
+ " lespontes USING (idPontes)"+
" LEFT OUTER JOIN "
+ " dbfécondation USING (idPontes)"+
" Order By " + " lespontes.Cage " + " ASC ",null);
if (cursor.moveToFirst()) {
do {
HashMap<String, String> hashMapData= new HashMap<String,
String>();
hashMapData.put("idPontes", cursor.getString(0));
hashMapData.put("Cage",cursor.getString(1));
hashMapData.put("Couvés",cursor.getString(2));
hashMapData.put("Fécondés", cursor.getString(3));
arrayListAllData.add(hashMapData);
} while (cursor.moveToNext());
}
return arrayListAllData;
}
Solution 1:[1]
Try using :-
Cursor cursor = database.rawQuery
(
" SELECT lespontes.idPontes ," +
" lespontes.Cage as Cage," +
" lespontes.Couvés," +
" dbfécondation.Fécondés " + "FROM (" +
" SELECT idPontes FROM lespontes" +
" UNION "
+ " SELECT idPontes FROM dbfécondation)" +
" LEFT OUTER JOIN"
+ " lespontes USING (idPontes)" +
" LEFT OUTER JOIN "
+ " dbfécondation USING (idPontes)" +
" Order By " + " lespontes.Cage " + " ASC ", null);
i.e. the parenthesises surrounding the SELECT have been embedded within the SQL. Also the useless line feeds (\n's) have also been removed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MikeT |
