Let's say i have 'db_institute' and 'tb_data' which have 39 Column
While This Answers Selecting from the last 10 column, i want to add extra column in the query
the result would be like this when i prepared statement it
SELECT Name,lastcolumn1,...,lastcolumn10 from tb_data
And here's my failed attempt
SELECT Name,
CONCAT('SELECT ',
GROUP_CONCAT(COLUMN_NAME),
' FROM 'tb_data')
FROM
(SELECT
COLUMN_NAME,
ORDINAL_POSITION
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_SCHEMA='db_institute'
AND
TABLE_NAME='tb_data'
ORDER BY
ORDINAL_POSITION DESC LIMIT 10) AS ord_desc
ORDER BY
ord_desc.ORDINAL_POSITION
into @sql
Which result error
Unknown column 'Name' in 'field list'
' FROM 'tb_data'. if error still persist, let us know. also why do you haveSELECT Namewhile you dont have any reference to thatNamecolumn, remove it maybe?SELECT Name? last 10 columns should be covered by the link you mentionedNameis from tb_data ? my bad didnt get you in the beginning, I'll post an answer soon