Q:

mysql SELECT from column with a concatenated string

I select something from a column named "9 stars" (without the "").
SELECT `9 stars` FROM `table` WHERE ... 

works fine, but I have to find a solution to do the job combining a variable (i = 9) with the "stars", something like:
i = 9;  
SELECT `i stars` FROM `table` WHERE ...  (which does not work like this, of course).

A:

If you want to do it in pure Sql then For Dynamic Column name you need to use prepare statement
SET @i =9;
SET @table = <tblname>;
SET @query = CONCAT('SELECT ',CONCAT('`',@i,' ', 'start','`'),' FROM ', @table);

PREPARE stmt FROM @query;
EXECUTE stmt;

check this
Dynamic conversion of string into column name. MySQL

A:

If you don't want to mess around with dynamically constructing your query AND know how many "i" values there are, you could just do this:
SET @i = whatever;
SELECT CASE @i 
   WHEN 1 THEN `1 stars`
   WHEN 2 THEN `2 stars`
   WHEN 3 THEN `3 stars`
   WHEN 4 THEN `4 stars`
   WHEN 5 THEN `5 stars`
   WHEN 6 THEN `6 stars`
   etc....
   ELSE NULL
END AS `the_stars`
FROM table
WHERE ...

You could also use the value from another field of the row instead of a session variable (@i)

