I'm attempting to execute a very long SQL statement that selects the "Top N" rows using a number of user options. I do not wish to post the whole statement here as it is very long but I am using MySQL variables as described in this post : MySql Query: Select top 3 rows from table for each category
The statement works fine when run on the MySQL command line BUT the issue I am having is that the whole query has to be run through a PDO connection and I wondered if someboody could confirm that I cannot set values 'on-the-fly' as illustrated below. Is this a PDO limitation? Have I just wasted a few hours? Many thanks for your help ...
SELECT outerseasons.* FROM (SELECT seasons.CountryName, seasons.idCountry, '' as idCountryGroup, '' as CGName, seasons.DIValue_WorkingEntered,
seasons.SNName, seasons.idSeason, seasons.idParameter, seasons.PMName,
CASE
WHEN @idSeason != seasons.idSeason OR @idParameter != seasons.idParameter
THEN @rownum := 1
ELSE @rownum := @rownum + 1
END AS rank,
@idSeason := seasons.idSeason as var_season,
@idParameter := seasons.idParameter as var_parameter
FROM ( SELECT ...