Hi,
When exporting to survey results a lot of operations are done by PHP code so there are no simple SQL queries to reuse. Just take a look at exportresults.php if you are interested.
If you want to query database directly there is a useful document with LS database structure:
docs.limesurvey.org/LimeSurvey+1.8+datab...meSurvey+development
To see data that you are interested to use as column headers try to run this:
select sid, gid, qid, parent_qid, question, title from Lime_questions where sid=XXXXX;
The problem with this query is that it returns data in columns so if you want to use it as headers and still use pure sql you may be forced to use something (really ugly) like this:
select
(select title from lime_questions where qid=25) as q1,
(select title from lime_questions where qid=26) as q2
from lime_questions limit 1;