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?

7 Replies

  • 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
    10 years ago

    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
    10 years ago

    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>

  • ronaksomani's avatar
    ronaksomani
    Mentor
    10 years ago

    VarunGrazitti   :List can have n number of board ids ranging any where from 0-25. So would perefer if there is any other solution for same. May be something like SELECT * FROM messages WHERE board.id NOT IN ('board-name'). NOT IN is part of SQL query. Is there any alternatives for this?

  • a more maintainable version:

     

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

     

  • irach15's avatar
    irach15
    Maven
    8 years ago

    ronaksomani

    did you find how to do this?

    I need it too, looking around and not able to find a simple one API call for all tkbs in specific category, all boards except one specific board.

  • 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>