简体   繁体   中英

Room Database Query for not equal

I'm trying to build a query for Room DB that finds all items except for a specific id. Well, no luck so far. I've tried both != and <> and the id is still coning through.

Query examples:

@Query("SELECT * FROM <table name> WHERE _id!=:id AND team=:team")

@Query("SELECT * FROM <table name> WHERE _id<>:id AND team=:team")

Any help is greatly appreciated.

Okay, so both != and <> do work for creating a Query where you want to exclude something that is not equal to the parameter that you're passing in. My issue was that I was running 2 separate queries concurrently and one of them need the id passed from the other. Changed the code to run one after the other finishes and all is good now.

Thanks again!

JP

Try this way..

    @Query("SELECT * FROM MyTable where id=:id and ItemPrice=:price")
List<MyTable> getData(int id,int price);

and also make sure define paremeter same as after : value like id then pass paremeter in id if pass nId then pass into paremeter nId.

second value paremeter same as define into query.

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