Forum Discussion

dustin's avatar
dustin
Expert
9 years ago

How do I exclude messages from a particular board using a LiQL query?

I would like to run a LiQL call where I retrieve the latest posts from the community, however I would like to exclude messages from a particular board.  The following query doesn't work as the error says != is not a valid operator. 

 

SELECT * FROM messages WHERE category.id='xxxxxxxx' AND board.id != 'test' AND depth=0 ORDER BY post_time DESC LIMIT 15

Does anyone have any other suggestions?

  • OlivierS's avatar
    OlivierS
    Lithium Alumni (Retired)

    dustin I haven't checked the documentation but I think you can use the clause 'IN', so:

     

    SELECT * FROM messages WHERE category.id IN ('xxxxxxxx','yyyyyyyy','zzzzzzzz')  AND depth=0 ORDER BY post_time DESC LIMIT 15
    

    It's not the best has you might add categories in the future, or you might have a long list of categories ...

     

    Another option is to run your request for all categories, then add a if statement to eliminate everything from your test category.

     

    SELECT * FROM messages WHERE  depth=0 ORDER BY post_time DESC LIMIT 15
    
    This isn't the correct freemarker syntax, just an idea:
    
    if message.board.id != 'test' then {do what you want to do with your messages }