Reputation: 13975
I have a mysql function
SELECT * FROM `stats` WHERE BETWEEN '2011-01-03' AND '2011-01-01' AND `email`='[email protected]' AND `city`='New York' AND `location`='New York' AND `date` GROUP BY action
However I can't seem to get it working, it works if I take out the BETWEEN '2011-01-03' AND '2011-01-01' but not with it in, how can I make this function work?
Upvotes: 3
Views: 32063
Reputation: 9199
Use column name before using between condition
Like As:
Date BETWEEN '2011-01-01' AND '2011-01-03'
In your SQL You Forgot to put "Date" Field before BETWEEN Keyword
Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Upvotes: 3
Reputation: 9
Add the time to the date:
$qAddDate = " AND (dCreated >= '".$_POST['datefrom']."' AND dCreated <= '".$_POST['dateto'].":23:59:59')";
Upvotes: 0
Reputation: 8744
Hei you should have WHERE date_column BETWEEN '2011-01-03' AND '2011-01-01'
put the exact name of your column instead of date_column
so you'll have
SELECT * FROM `stats` WHERE `your_date_column` BETWEEN '2011-01-03' AND '2011-01-01' AND `email`='[email protected]' AND `city`='New York' AND `location`='New York' AND `date` GROUP BY action
Upvotes: 2
Reputation: 583
SELECT * FROM `stats` WHERE COLUMN-NAME-HERE BETWEEN
Notice COLUMN-NAME-HERE you need the date field
Upvotes: 2
Reputation: 212835
WHERE BETWEEN '2011-01-03' AND '2011-01-01'
needs a column name to be compared. Is it the date
column?
Then your query should look like this:
SELECT *
FROM `stats`
WHERE `date` BETWEEN '2011-01-01' AND '2011-01-03'
AND `email`='[email protected]'
AND `city`='New York'
AND `location`='New York'
GROUP BY action
Upvotes: 11
Reputation: 125466
add the name of date field and
then
change the order
date BETWEEN '2011-01-01' AND '2011-01-03'
first the earliest day and after that the latest date
Upvotes: 3