2013-01-12 36 views
-1

我基本上試圖MySQL查詢 我的新的當前查詢作爲跟隨MySQL的「不」查詢引發錯誤

SELECT `o`.`id`, `o`.`name`, `o`.`url`, `o`.`type`, `o`.`desc` FROM `offers` as `o` 
WHERE `o`.country_iso = '$country_iso' AND `o`.`id` not in 
(select distinct(offer_id) from conversions where ip = '$_SERVER[REMOTE_ADDR]' 
and converted != '0') AND `o`.`id` not in 
(select `offer_id` from `aff_disabled_offers` where `offer_id` = 'o.id' 
and `user_id` = '1') ORDER by rand() LIMIT $limit 

查詢工作期間不要使用函數兩次,但由於某種原因,它是完全忽略這個

AND `o`.`id` not in 
(select `offer_id` from `aff_disabled_offers` where `offer_id` = 'o.id') 
+2

希望你嘗試添加'而不是...' – agim

+0

什麼是完整的錯誤消息? –

+0

閱讀關於引用:http://stackoverflow.com/questions/11321491/mysql-when-to-use-single-quotes-double-quotes-and-backticks/11321508#11321508 –

回答

1

您需要在您的條件之間指定一個運算符,如AND或OR。您還需要在NOT IN子句中使用有效的查詢。

SELECT `o`.`id`, `o`.`name`, `o`.`url`, `o`.`type`, `o`.`desc` 
FROM `offers` as `o` 
WHERE `o`.country_iso = '$country_iso' 
AND `o`.`id` not in (select distinct(offer_id) 
        from converstions where 
        from conversions 
        where ip = '$_SERVER[REMOTE_ADDR]' 
        and converted != '0') 
AND `o`.`somevar` not in (select `somevar` from 
          `sometable` where `offer_id` = 'o.id') 
ORDER by rand() LIMIT 0,6 
+0

這不工作,或者由於某種原因,這裏是我使用的代碼是'\t \t \t $ sql =「SELECT'o'.''','''''''''''''''''''''''''','''''''''' desc' FROM'offers' as'o' where'o'.country_iso ='$ country_iso' \t \t \t AND'o'.''' not in(select distinct(offer_id)AND'o'.'id' not在(從'aff_disabled_offers'其中 \t \t \t'offer_id' = 'o.id' 和選擇''offer_id' = user_id' '1') \t \t \t FROM convers其中ip ='$ _SERVER [REMOTE_ADDR]'並轉換!='0')order by rand()「;' –

+0

我的帖子中的一些代碼被放錯了位置。正如你所看到的(select distinct(offer_id)是不完整的。我現在更新了我的答案。 –

+0

我已經更新了我當前的帖子來解釋此刻的問題 –