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

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Select rows when all all ids of its children records matches
Date: 2018-09-12 15:28:27
Message-ID: fe916369-aa51-0e7b-3afa-eb89974dfcc4@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Maybe this:
select p.id, p.name
from posts p,
     posts_tags pt,
     tags t
where t.id in (1, 2, 3)
  and t.id = pt.tag_id
  and pt.post_id = p.id;

On 09/12/2018 10:23 AM, Arup Rakshit wrote:
> I have a table posts(id, name), posts_tags(post_id, tag_id) and tags (id,
> name) ... I want to get all posts which has tag id 1, 2 and 3 for example.
> How should I do this? I tried ALL, but it didn’t work.
>
> Those tag ids comes from UI by users, so I am looking for generic approach.
>
>
> Thanks,
>
> Arup Rakshit
> ar(at)zeit(dot)io <mailto:ar(at)zeit(dot)io>
>
>
>

--
Angular momentum makes the world go 'round.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Arup Rakshit 2018-09-12 15:30:46 Re: Select rows when all all ids of its children records matches
Previous Message Arup Rakshit 2018-09-12 15:23:34 Select rows when all all ids of its children records matches