pratik
pratik

Reputation: 4479

iPhone + sqlite3 + not in query

I want to write a in query in my code. My query is something like:

SELECT  PlayerID, PlayerName, Type, BattingSkills, BallingSkills 
from Player 
where TeamId = 6 
      and PlayerID not in (163,174) 
order by battingSkills desc 
limit 4

In my xCode I am writing the query like below

const char *sql = "SELECT  PlayerID, PlayerName, Type, BattingSkills, BallingSkills                                                                    from Player where TeamId = ? LIMIT 11";

sqlite3_stmt *selectstmt;
if(sqlite3_prepare_v2(database, sql, -1, &selectstmt, NULL) == SQLITE_OK) 
{
    sqlite3_bind_int(selectstmt, 1, teamId);
    ..................
    }

Now suppose I want to write the not in query (as my SQL query above), how will I write my code in xCode to pass the not in IDs.

Upvotes: 0

Views: 1088

Answers (1)

Vladimir
Vladimir

Reputation: 170839

This may work (pass the values the same way you do with teamID):

const char *sql = "SELECT  PlayerID, PlayerName, Type, BattingSkills, BallingSkills from Player where TeamId = ? and playerID not in (?, ?) LIMIT 11";
...
sqlite3_bind_int(selectstmt, 1, teamId);
sqlite3_bind_int(selectstmt, 2, notID1);
sqlite3_bind_int(selectstmt, 3, notID2);

Upvotes: 2

Related Questions