Get SQL query results as variables

Hello,

Example - I have column Student ID , Fname and Lname - I want to get top 10 student ID and I want to write to excel -

How to get only column data to excel?

Thank you