(0000063)
douglasw (administrator)
2008-08-13 15:39
|
Found on the net:
I am trying to run the following command on mysql 4.0.25 :
SELECT COUNT(a.id) FROM steers_content AS a INNER JOIN steers_content_frontpage AS f ON f.content_id = a.id INNER JOIN steers_categories AS cc ON cc.id = a.catid INNER JOIN steers_sections AS s ON s.id = a.sectionid LEFT JOIN steers_users AS u ON u.id = a.created_by LEFT JOIN steers_groups AS g ON a.access = g.id WHERE a.state = 1 AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '2007-02-05 22:18' ) AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2007-02-05 22:18' ) AND s.published = 1 AND cc.published = 1 AND a.access <= 2 AND s.access <= 2 AND cc.access <= 2 AND a.id NOT IN (SELECT DISTINCT ArticleID FROM steers_contentviews WHERE UserID = 62)
It gives an error. If I remove the last part of the query: AND a.id NOT IN (SELECT DISTINCT ArticleID FROM steers_contentviews WHERE UserID = 62) then it works fine. So I assume that this version of mysql does not support the "not in" part of the query.
Do you know of another way of rewording the query so that mysql 4.0.25 will accept it? (By the way, I am running a later version of mysql on my test machine and the query runs fine but the live server is only running mysql 4.0.25)
ANSWER:
Subqueries were not supported until version 4.1
to the FROM list, add LEFT JOIN steers_contentviews ON a.id = ArticleID AND UserID = 62
and then to the WHERE clause, add AND steers_contentviews.ArticleID IS NULL
-------------------------
Thus changed the following SQL:
$sql = sprintf("SELECT profile_id, username, last_login_time FROM " . $phpraid_config['db_prefix'] . "profile " .
"WHERE profile_id NOT IN " .
"(SELECT profile_id FROM " . $phpraid_config['db_prefix'] . "signups " .
"WHERE raid_id = %s)", quote_smart($raid_id));
To:
$sql = sprintf("SELECT a.profile_id, a.username, a.last_login_time " .
"FROM " . $phpraid_config['db_prefix'] . "profile AS a " .
"LEFT JOIN " . $phpraid_config['db_prefix'] . "signups ON a.profile_id = " . $phpraid_config['db_prefix'] . "signups.profile_id " .
"AND " . $phpraid_config['db_prefix'] . "signups.raid_id = %s " .
"WHERE " . $phpraid_config['db_prefix'] . "signups.profile_id IS NULL", quote_smart($raid_id)); |