简体   繁体   中英

SQL Help - Incorrect syntax near the keyword 'EXISTS'

I am having issues with my sql (I am relatively new to sql). I cannot figure out why I am getting a syntax error. Any help would be appreciated.

Thanks in advance.

SELECT *
FROM table_name_1
WHERE
column_A IN ('Lorem', 'Ipsum', 'Test') 
AND column_B NOT EXISTS
    (
    SELECT column_C 
    FROM table_name_2
    WHERE Date  >= CURDATE()
    )

You cannot compare NOT EXISTS with a column value.

SELECT *
FROM table_name_1
WHERE
column_A IN ('Lorem', 'Ipsum', 'Test') 
AND NOT EXISTS
    (
    SELECT 1 
    FROM table_name_2
    WHERE Date  >= CURDATE()
    AND column_c = column_b
    )

or use IN

SELECT *
FROM table_name_1
WHERE
column_A IN ('Lorem', 'Ipsum', 'Test') 
AND column_B NOT IN
    (
    SELECT column_C 
    FROM table_name_2
    WHERE Date  >= CURDATE()
    )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM