Forum Discussion

ronaksomani's avatar
10 years ago

how to exclude posts with certain board ids

Hello,

I want to execute a query where I can exclude posts from given board ids. I tried below approach :

SELECT * FROM messages WHERE board.id NOT IN ('board-name')

 

But getting exception that it is invalid query syntax. Can any one suggest how can it be implemented?

  • ronaksomani irach15  There is no such query which can help you out to exclude specific board/category. But alternatively, you can achieve it by using change in community structure.

    Option 1:

      Like you can create 2 categories i.e. Category1 & Category2.
    Category1 will contain boards which you want to exclude.  Category2 will contain rest of the boards.

    Now you can use the query
    Select * from message where category.id='Category2'

     

    Option 2:

    <#assign excIds = ["Id1", "Id2","Id3"] />
    <#assign boards = rest( "2.0", "/search?q=" + "select * from boards"?url).data />
    <#list boards.items as board>
    <#if excIds?seq_index_of(board.id)== -1 >
    //do something here
    </#if>
    </#list>

  • a more maintainable version:

     

    <#assign excIds = ["Id1", "Id2","Id3"] />
    
    <#if excIds?seq_index_of(boardId)== -1 >
    
     //do something here
    </#if>

     

  • ronaksomani - Try this instead, you dont need to use V2 for this, simple if condition can do this.

     

    <#if boardID != "exclude_board">
    //run you query here
    SELECT * FROM messages WHERE board.id = 'boardID'
    </#if>

     

    • ronaksomani's avatar
      ronaksomani
      Mentor

      VarunGrazitti  : Can I pass list of board-ids to that if condition? As my requirement is to filter all those posts which have mentioned board-ids. Here I can have multiple board-ids which I want to filter.

      • VarunGrazitti's avatar
        VarunGrazitti
        Boss

        ronaksomani - how long is the list of the boards to exclude? you can use or condition as below:

         

        <#if boardID != "exclude_bd1" || boardID != "exclude_bd2" || boardID != "exclude_bd3">

        </#if>