select table and replace column fields by value from multiple tables in mysql
You could change sample_id, like below:

DROP TABLE TableData_elements;
CREATE TABLE TableData_elements
 (Dataid INT,
 sample_id CHAR(10),
 sample_title TEXT               
 );
INSERT INTO TableData_elements VALUES
('400','1','Fname'),
('400','2','Sname'),
('400','3','Lname'),
('400','4_1','first'),
('400','4_2','second'),
('400','4_3','third');


OR you could change query at the end:

SELECT  
  CONCAT( 'SELECT ', 
          GROUP_CONCAT(CONCAT('sample_', 
                              te.sample_id, 
                              CASE WHEN teo.option_id&gt;0 THEN 
                                    CONCAT('_',teo.option_id) 
                                    ELSE '' END, 
                              ' ', 
                              sample_title)),
          ' FROM TableData_400' ) 
FROM TableData_elements te 
LEFT JOIN TableData_elements_options teo ON 
        teo.Dataid=te.Dataid and 
        teo.sample_id=te.sample_id ;


EDIT: (also tak not of optionss):

SELECT  
  CONCAT( 'SELECT ', 
          GROUP_CONCAT(CONCAT('sample_', 
                              te.sample_id, 
                              CASE WHEN teo.option_id&gt;0 THEN 
                                    CONCAT('_',teo.option_id) 
                                    ELSE '' END, 
                              ' ', 
                              CASE WHEN teo.option_id&gt;0 THEN
                                 teo.optionss
                              ELSE sample_title END)),
          ' FROM TableData_400' ) 
FROM TableData_elements te 
LEFT JOIN TableData_elements_options teo ON 
        teo.Dataid=te.Dataid and 
        teo.sample_id=te.sample_id ;