change from an OR to an AND condition

change from an OR to an AND condition

am 27.09.2011 15:46:06 von Simon Wilkinson

--0016e659f2364ca8db04adec7f04
Content-Type: text/plain; charset=ISO-8859-1

Hi,

I have a query where I'm using a left outer join to connect two tables,
entries and entries_tags, where entries_tags is a join table between entries
and another table, tags. In my query I am selecting values from the entries
table where the entries have any of the provided tags - WHERE
entries_tags.tag_id IN (x, y, z)

What I would like to do is switch this from an OR condition to an AND
condition, so that an entry is only returned if it has all of x, y, and z.

How would I go about doing this?

Thanks,

Simon

--0016e659f2364ca8db04adec7f04--

Re: change from an OR to an AND condition

am 27.09.2011 17:02:44 von Simon Wilkinson

--001636416aa55afd8b04aded914a
Content-Type: text/plain; charset=ISO-8859-1

Just to clarify, here is some more info:

Here is what the query looks like:

SELECT DISTINCT `entries`.id FROM `entries` LEFT OUTER JOIN `entries_tags`
ON `entries_tags`.entry_id = `entries`.id LEFT OUTER JOIN `tags` ON
`tags`.id = `entries_tags`.tag_id WHERE (`entries_tags`.tag_id IN (5,6));

So in this instance, what I'm looking for are the entries where they have
two entries in entries_tags with tag ids 5 and 6, instead of entries that
have either.

Thanks again,

Simon

On 27 September 2011 09:46, Simon Wilkinson wrote:

> Hi,
>
> I have a query where I'm using a left outer join to connect two tables,
> entries and entries_tags, where entries_tags is a join table between entries
> and another table, tags. In my query I am selecting values from the entries
> table where the entries have any of the provided tags - WHERE
> entries_tags.tag_id IN (x, y, z)
>
> What I would like to do is switch this from an OR condition to an AND
> condition, so that an entry is only returned if it has all of x, y, and z.
>
> How would I go about doing this?
>
> Thanks,
>
> Simon
>
>
>

--001636416aa55afd8b04aded914a--