Forum Moderators: coopster

Message Too Old, No Replies

My SQL Query Problem

SQL Query regarding INNER JOINS

         

Weirfire

3:46 pm on Apr 5, 2005 (gmt 0)

10+ Year Member



I'm trying to write a MySQL query for my PHP file and wondered if anyone could solve the problem.

It's a little trickier than usual but I'll try to explain it and show what I have come up with already.

Table A fields : ID and Variable
Table B fields : ID and Status

What I would like is a query which shows a count of the number of results we get from Variable being X from table A and where the Status is not StatusA or StatusB.

So far the query which I've come up with is

$Result = mysql_query(
"SELECT COUNT(*) AS count
FROM TableA
INNER JOIN TableB ON TableA.ID = TableB.ID
WHERE TableA.Variable = '$X'
AND TableB.Status!== 'StatusA' ¦¦ TableB.Status!== 'StatusB'"
);

How am I doing with this query?

MamaDawg

5:29 pm on Apr 5, 2005 (gmt 0)

10+ Year Member




WHERE TableA.Variable = '$X'
AND TableB.Status!== 'StatusA' ¦¦ TableB.Status!== 'StatusB'"

I think you want an AND instead of an OR as the final condition in your WHERE clause ...

AND TableB.Status!= 'StatusA' AND TableB.Status!= 'StatusB' ...

Shorter way to write it:

AND TableB.Status NOT IN ('StatusA', 'StatusB') ...