PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 23, 2022

[FIXED] phpMyAdmin shows MySQL returned an empty result set for Variable Declarations

 January 23, 2022     mysql, phpmyadmin     No comments   

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!

enter image description here


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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing