0

I have been looking at this statement for ages and simply cannot find the error can you guys help?

        SELECT XD.*, UhED.row_class,
            (SELECT id
                FROM Comment C
                WHERE C.Excel_Data_Excel_Lists_id = XD.Excel_Lists_id
                    AND C.Excel_Data_row = XD.row
                LIMIT 1
            ) AS has_activity
        FROM User_has_Excel_Lists UhXL
        JOIN Excel_Lists XL
            ON XL.id = UhXL.Excel_Lists_id
        JOIN Excel_Data XD
            ON XD.Excel_Lists_id = XL.id
        LEFT JOIN User_has_Excel_Data UhED
            ON UhED.Excel_Data_Excel_Lists_id = XL.id
                AND UhED.Excel_Data_row = XD.row
                AND UhED.User_id = 1
        WHERE UhXL.User_id = 1
            AND XL.created > DATE_SUB(DATE(now()), INTERVAL 2)<-- it says that the error is here
        GROUP BY XD.telephone 
        ORDER BY last_name ASC, first_name ASC
2
  • Is DATE(NOW()) a bit like CURDATE()? And INTERVAL 2 WHAT? Commented Mar 25, 2014 at 9:38
  • you should mention the day or month or year..DATE_SUB(DATE(now()), INTERVAL 2) Commented Mar 25, 2014 at 9:42

4 Answers 4

1
 AND XL.created > DATE_SUB(DATE(now()), INTERVAL 2 DAY)

try this it may help you

Sign up to request clarification or add additional context in comments.

Comments

1

You forgot do specify the interval unit maybe? Something like INTERVAL 2 DAY or INTERVAL 2 HOUR maybe?

Comments

0

You may need to specify the measure for the interval (e.g., days, months, etc.)

You can check the syntax for DATE_SUB here

Comments

0

if i understand your problem like follow this instructions as: you should must mention the day, month, hour, or year in the following line:

your code:

 AND XL.created > DATE_SUB(DATE(now()), INTERVAL 2) 

change code: DAY

AND XL.created > DATE_SUB(DATE(now()), INTERVAL 2 DAY) 

if you are using the DATE(tablename) in your table you getting error like:

WRONG CODE (sample)(http://sqlfiddle.com/#!2/5b7e2/7):check the code no:5

SELECT id,DATE_SUB(DAT(NOW()), INTERVAL 2 DAY) 
FROM supportContacts;  

RIGHT CODE:

SELECT id,DATE_SUB(DATE(NOW()), INTERVAL 2 DAY) 
FROM supportContacts;

REFER THIS LINK: http://sqlfiddle.com/#!2/5b7e2/7

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.