Q:

Android - passing field name as selectionArgs to rawQuery

I'm passing the below statement as a rawQuery in Android:    
SELECT DISTINCT ltUsers._id,ltUsers.NAME,ltUsers.GLOBAL_ID, ltGroups.GROUP_NAME
        FROM ltUsers
        JOIN ltGroups ON (ltUsers.GROUP_ID = ltGroups.GLOBAL_ID)    
        WHERE ltgroups.GLOBAL_ID = ? " +
        ORDER BY ltUsers.NAME ASC,ltgroups.GLOBAL_ID ASC;

With the rawQuery as follows:
Cursor c = db.rawQuery(sql,args)

It works just fine if I pass a value to the parameter, e.g.
String[] args = new String[]{"2"}

However, I also want to be able to show all rows, unlimited by the GLOBAL_ID in the WHERE clause. Testing on a dump of my SQLite database outside of Android - as well as in Android by just writing the parameter directly into the statement - shows the following clause to be a valid way to do this:
WHERE ltGroups.GLOBAL_ID = ltGroups.GLOBAL_ID

Yet when I pass the field reference ltGroups.GLOBAL_ID or [ltGroups].[GLOBAL_ID] as a parameter it fails to return any rows in the rawQuery. Any ideas on why this might be happening? Happy to produce any extra information.

A:

Parameters always replace specific values, not anything else.
When you put the string "ltGroups.GLOBAL_ID" into the parameters array, it is interpreted as exactly that, a string.
(To show all records, just omit the WHERE clause.)

