简体   繁体   中英

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM