Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

the between clause

 
Mahesh Lohi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

My am getting an error for the following mysql syntax



Error:

right syntax to use near 'mydate BETWEEN 20091226 AND 20091226 GROUP BY item_name' at line 1

Thank you in advance
 
Praveen Rajendran
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I guess the problem is you missed an AND between the where clauses salesman and mydate.

select item_name,SUM(qty),SUM(total_amt) from invoice where salesman=? mydate BETWEEN ? AND ? GROUP BY item_name"


I guess the below code would work.. let me know..

select item_name,SUM(qty),SUM(total_amt) from invoice where salesman=? and mydate BETWEEN ? AND ? GROUP BY item_name
 
Scott Selikoff
author
Saloon Keeper
Posts: 4010
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For purposes of creating more-standard SQL queries I recommend you replace "X BETWEEN Y AND Z" syntax with "X > Y AND X < Z". At the very least it gives you better control over inclusive (<=,>=) searches as well as creates code that works better on more systems. Least of which, I find the syntax of both to be similar. Anyone have reasons for strongly recommend ever using the keyword BETWEEN?
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Behaviour of BETWEEN is vendor specific.It might pick only the values in between the boundary values provided or includes both boundary values as well or .... BETWEEN
 
Mahesh Lohi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for those replies.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic