Search Postgresql Archives

Re: Select rows when all all ids of its children records matches

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I tried :

WITH posts_tags_cte AS (
        SELECT post_id, array_agg(tag_id) as tags
        FROM posts_tags
        WHERE tag_id in (1, 2)
        GROUP BY post_id
)
SELECT posts.id FROM posts_tags_cte JOIN posts ON posts.id = posts_tags_cte.post_id
WHERE posts_tags_cte.tags @> array[1, 2]::int8[]

But it gives me all the posts.


Thanks,

Arup Rakshit



On 12-Sep-2018, at 9:14 PM, Arup Rakshit <ar@xxxxxxx> wrote:

Can you show me the SQL construction? Do I need to use `WITH`?


Thanks,

Arup Rakshit



On 12-Sep-2018, at 9:13 PM, David G. Johnston <david.g.johnston@xxxxxxxxx> wrote:

On Wednesday, September 12, 2018, Arup Rakshit <ar@xxxxxxx> wrote:
IN is OR, I want the AND logic. Select posts which has tag 1, 2 and 3 ( tag ids )

Build arrays and then use the “contains” operator.

David J. 



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux