2

I have following query, but it gives me errors, if anyone could give me a hint, would be awesome.

SELECT tblinvoices.*,companyname FROM tblinvoices INNER JOIN tblclients 
ON tblclients.id=tblinvoices.clientid 
WHERE 1=1 AND date between '20111201' to '20111208' 

The error message is:

Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TO '20111208''

2
  • what's the data type of your date field? Commented Dec 10, 2011 at 16:30
  • I've edited the question and added the error message for you. Next time try not to be so lazy. Commented Dec 10, 2011 at 18:02

3 Answers 3

2

use AND instead of TO in the BETWEEN command.

SELECT tblinvoices.*,companyname FROM tblinvoices INNER JOIN tblclients 
ON tblclients.id=tblinvoices.clientid 
WHERE 1=1 AND date between '20111201' AND '20111208' 
Sign up to request clarification or add additional context in comments.

Comments

0

I am pretty sure is the word TO, it should be:

SELECT tblinvoices.*,companyname FROM tblinvoices INNER JOIN tblclients ON tblclients.id=tblinvoices.clientid WHERE 1=1 AND date between '20111201' AND '20111208'

Comments

0

If companyname is from tblinvoices it should work, otherwise you need to check where companyname comes from. And the syntax for between is like this

date between '20111201' and '20111208'

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.