Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

192.168.1.41:8000, Www.xxxcon., %s wwwxxxcon, %s wwwxxxcon, www.xxxcon, xxxxdup, bitlord outgoing port settings, ckowwwxxx, 192.168.1.41:8000/nor-482.html, php.ini "Unable to initialize module"

Links

XODOX
Impressum

#1: change from an OR to an AND condition

Posted on 2011-09-27 15:46:06 by 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--

Report this message

#2: Re: change from an OR to an AND condition

Posted on 2011-09-27 17:02:44 by 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 <simon.wilkinson@gmail.com>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--

Report this message