Select error with left Join

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Catzwolf
Forum Newbie
Posts: 5
Joined: Tue Aug 31, 2004 12:30 am

Select error with left Join

Post by Catzwolf »

Code: Select all

SELECT a.* FROM table_a a LEFT JOIN table_b b ON b.lid=a.lid WHERE a.published > 0 AND a.published <= 1118827824 AND (a.expired = 0 OR a.expired > 1118827824) AND a.offline = 0 AND b.cid=a.cid OR (a.cid=1 OR b.cid=1) ORDER BY published DESC
I am having problems getting this query to work correctly, while the actually join seems to work, for some reason it ignores this part of the query and displays published, expired or online regardless of what is actually stored in these fields:

Code: Select all

WHERE a.published > 0 AND a.published <= 1118827824 AND (a.expired = 0 OR a.expired > 1118827824) AND a.offline = 0
Many thanx for your help

John
Catzwolf
Forum Newbie
Posts: 5
Joined: Tue Aug 31, 2004 12:30 am

Re: Select error with left Join

Post by Catzwolf »

Catzwolf wrote:SELECT a.* FROM table_a a LEFT JOIN table_b b ON b.lid=a.lid WHERE a.published > 0 AND a.published <= 1118827824 AND (a.expired = 0 OR a.expired > 1118827824) AND a.offline = 0 AND b.cid=a.cid OR (a.cid=1 OR b.cid=1) ORDER BY published DESC

I am having problems getting this query to work correctly, while the actually join seems to work, for some reason it ignores this part of the query and displays published, expired or online regardless of what is actually stored in these fields:

WHERE a.published > 0 AND a.published <= 1118827824 AND (a.expired = 0 OR a.expired > 1118827824) AND a.offline = 0

Many thanx for your help

John
Should have been:

Code: Select all

SELECT a.* FROM table_a a LEFT JOIN table_b b ON b.lid = a.lid
WHERE a.published > 0 AND a.published <= 1118834480
AND (a.expired = 0 OR a.expired > 1118834480)
AND a.offline = 0
AND (b.cid=a.cid OR (a.cid=1 OR b.cid=1))
ORDER BY published DESC
Post Reply