2013-01-05 79 views
0

即時通訊使用以下SQL查詢但我不斷收到錯誤內部連接查詢中的MySQL語法錯誤1064

您的SQL語法錯誤;檢查對應於你的MySQL服務器版本使用「」附近

SELECT roomID 
FROM rooms 
WHERE 
roomID NOT IN (
    SELECT t1.roomID 
    FROM 
    rooms t1 
    INNER JOIN reservations t2 ON t1.roomID = t2.roomID 
    INNER JOIN reservationdetails t3 ON t2.resDeID = t3.resDeID 
    WHERE NOT ('2013-01-13' < t3.arrival OR ('2013-02-03' > t3.departure) 
) 

我不是一個很好的SQL程序員正確的語法手冊..做了所有該上的SQL讀了很多以後。

是,如果有人能想出什麼錯在這裏有很大的幫助..

在此先感謝..

+3

看起來你缺少另一收盤')'後'OR('2013-02-03> t3.departure)' –

+1

你錯過了''' –

回答

1

你錯過了一個閉合)

變化

WHERE NOT ('2013-01-13' < t3.arrival OR ('2013-02-03' > t3.departure) 

WHERE NOT ('2013-01-13' < t3.arrival OR ('2013-02-03' > t3.departure)) 
+0

狗屎..感謝一百萬倍!看起來lyk沒有睡眠得到了我失去了更好的..再次感謝傢伙! –

2

看起來,至少,你缺少)

0

你的問題是在這裏

WHERE NOT ('2013-01-13' < t3.arrival OR ('2013-02-03' > t3.departure) 

嘗試那樣做

WHERE t3.arrival >= '2013-01-13' OR t3.departure <= '2013-02-03' 
+2

'WHERE NOT(a或b)'等於'WHERE(NOT a)** AND **(NOT b)' –

0

你應該總是關閉所有打開的括號,好像你錯過了一個。

SELECT roomID 
FROM rooms 
WHERE 
roomID NOT IN (
    SELECT t1.roomID 
    FROM 
    rooms t1 
    INNER JOIN reservations t2 ON t1.roomID = t2.roomID 
    INNER JOIN reservationdetails t3 ON t2.resDeID = t3.resDeID 
    **WHERE NOT ('2013-01-13' < t3.arrival OR ('2013-02-03' > t3.departure)** 
) 

您可以刪除不和或像下面

WHERE t3.arrival >= '2013-01-13' OR t3.departure <= '2013-02-03' 

或增加一個支架之間的括號..

WHERE NOT ('2013-01-13' < t3.arrival OR ('2013-02-03' > t3.departure))