From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: Select rows when all all ids of its children records matches
Date: Wed, 12 Sep 2018 10:28:27 -0500
Message-ID: <fe916369-aa51-0e7b-3afa-eb89974dfcc4@gmail.com> (raw)
In-Reply-To: <FF55BC81-BB56-45C3-BCA2-B7D0F8E81F4A@zeit.io>
References: <FF55BC81-BB56-45C3-BCA2-B7D0F8E81F4A@zeit.io>
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@zeit.io <mailto:ar@zeit.io>
>
>
>
--
Angular momentum makes the world go 'round.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: ronljohnsonjr@gmail.com
Subject: Re: Select rows when all all ids of its children records matches
In-Reply-To: <fe916369-aa51-0e7b-3afa-eb89974dfcc4@gmail.com>
References: <FF55BC81-BB56-45C3-BCA2-B7D0F8E81F4A@zeit.io> <fe916369-aa51-0e7b-3afa-eb89974dfcc4@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox