Won't putting the first OR in parenthesis, fix it up?

SELECT t1.title, t2.auth_name FROM t1, t2, WHERE (cat_id = 1 OR cat_id = 2)
AND t1.auth_id = t2.auth_id

KL

Sam Folk-Williams wrote:

> Hi,
>
> I keep having this fundamental problem. It seems like this should be
> easy enough, but whenever I have a query where I'm using OR in the WHERE
> clause and the query is performed on multiple tables, I get strange
> results. For example:
>
> SELECT t1.title, t2.auth_name FROM t1, t2, WHERE cat_id = 1 OR cat_id =
> 2 AND t1.auth_id = t2.auth_id
>
> I want this query to give me a list of all article titles from a content
> table (t1) and the author's name from a people table (t2) where, the
> author ID from t1 matches that of t2, AND the article is either from
> Category 1 or Category 2. What I get instead, though, is every possible
> combination of article titles and author names from both tables. So, if
> there were 10 authors in t2, each title would be listed 10 times, once
> with each author name.
>
> Should I be using a different JOIN syntax? Am I totally mis-using the OR
> operator?
>
> Note that if I only want results from one category (i.e.: SELECT
> t1.title, t2.auth_name FROM t1, t2, WHERE cat_id = 1 AND t1.auth_id =
> t2.auth_id) everything works just fine.
>
> Thanks for any help,
>
> Sam
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to