Android Question SQL WHERE clause sintax error

FERNANDO SILVEIRA

Active Member
Licensed User
Hello guys,

I have the following SQL JOIN statement
B4X:
SELECT A.NamePerson AS "Person", B.NamePerson || " e " || C.NamePerson AS "Dads" FROM Persons A 
   LEFT JOIN Persons B ON A.CodMom = B.CodPerson 
   LEFT JOIN Persons C ON A.CodDad = C.CodPerson 
   ORDER BY A.NamePerson
That works fine producing the expected result. However, I decided to apply the following: WHERE A.NamePerson LIKE "M%" at the end and then I get an SQL sintax error.

B4X:
SELECT A.NamePerson AS "Person", B.NamePerson || " e " || C.NamePerson AS "Dads" FROM Persons A 
   LEFT JOIN Persons B ON A.CodMom = B.CodPerson 
   LEFT JOIN Persons C ON A.CodDad = C.CodPerson 
   ORDER BY A.NamePerson 
   WHERE A.NamePerson LIKE "M%"
The same sintax error also happens if I put WHERE clause right after the FROM Persons A.

This seems to be a bad SQL understanding from my side because this error also happens when I try it using SQLITE EXPERT database interface.

Can someone teach me how to implement this WHERE condition in my SELECT JOIN?

** Activity (main) Resume **
Error occurred on line: 145 (DBUtils)
android.database.sqlite.SQLiteException: near "WHERE": syntax error (code 1): , while compiling: SELECT A.NomePessoa AS Pessoa, B.NomePessoa || ' e ' || C.NomePessoa As Pais FROM PESSOAS A LEFT JOIN PESSOAS B ON A.CodMae = B.CodPessoa LEFT JOIN PESSOAS C ON A.CodPai = C.CodPessoa ORDER BY A.NomePessoa WHERE A.NomePessoa LIKE 'M%'
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
(near "WHERE": syntax error (code 1): , while compiling: SELECT A.NomePessoa AS Pessoa, B.NomePessoa || ' e ' || C.NomePessoa As Pais FROM PESSOAS A LEFT JOIN PESSOAS B ON A.CodMae = B.CodPessoa LEFT JOIN PESSOAS C ON A.CodPai = C.CodPessoa ORDER BY A.NomePessoa WHERE A.NomePessoa LIKE 'M%')
#################################################################

Regards,
Fernando
 
Top