We have an awesome eclipse plugin which is available for you to perform this. In this blog post, I am demonstrating how to install it and to generate a sample query.
For more information please have a look here.
Steps :
1. Install Eclipse IDE for Java developers
2. Launch Eclipse and select Help -> Install New Software
3. Click Add and in the repository dialog box, set the name to Force.com IDE and the location to https://developer.salesforce.com/media/force-ide/eclipse45. For Spring ’16 (Force.com IDE v36.0) and earlier Force.com IDE versions, use http://media.developerforce.com/force-ide/eclipse42.
4. Select IDE and click on Next to install.
5. Accept terms and Finish.
6. Restart the Eclipse.
7. When Eclipse restarts, select Window -> Open Perspective -> Other and Select Force.com and then click OK.
8. Now go to File -> New -> force.com project and provide your credentials to login to your salesforce account.
9. Click Next and it will create a project on the left pane.
10. Double click and open the schema and it will load the editor.
11. Now you can click on the preferred SF object and its fields. It will generate the SF query accordingly. Then you can run it.
Reference: https://developer.salesforce.com/docs/atlas.en-us.eclipse.meta/eclipse/ide_install.htm