Issue
I have a SQL query that starts with a SET command to set a variable so I don't have to go find it in the script every time.
SET @startdate = '2016-11-01';
SET @enddate = '2016-11-26';
SELECT stuff
FROM table
When I run the query via phpMyAdmin I get 3 result sets because it treats the variable SET command as separate queries. (screenshot below)
Down below the first two showing the warning I do get my data just fine. I'm just trying to figure out how I can not see the first two empty result sets if that's possible.
I don't know if this is a mySQL thing or a phpMyAdmin thing but any help would be great.
Thanks!
Solution
You can use a set the variables in a subquery and use cross join with the table to use them.
select stuff
from table
cross join (
select @startdate := '2016-11-01',
@enddate := '2016-11-26'
) t
where date_added between @startdate and @enddate
Answered By - Gurwinder Singh
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.