Save query results as csv


#1

Hi:
I am utterly new to sql and am using DB Browser for SQLite
My queries run fine but I cannot figure out how to export the results.
When I select CSV export from the File menu all I get is the query rather than the manipulated data…
I would truly appreciate someone explaining what I am doing wrong!
Joe


#2

@Joe_Foley

Thanks for posting. Let me preface my response with: We (Zetetic) didn’t create DB Browser for SQLite

I’m unsure if the desired functionality exists within the current interface but @justinclift would know for sure.

You could adjust your query to create a new table based on your current SELECT statement and then print out the newly created table as a CSV.

So take this example table:

Sample_Books_Table

Let’s say the query you want to export is:

SELECT title, author FROM books WHERE price > 10;

You could adjust it to be:

CREATE TABLE books_10 AS SELECT title, author FROM books WHERE price > 10;

Which would generate a table like:

books_10_table

Then you can go to File → Export → Export Table(s) as CSV and select the newly created table generated by your query (books_10) in the example here.

After exporting you’ll most likely want to run a query to discard the table that was created by the SELECT statement, something like:

DROP TABLE books_10;

Hope this helps!

Cheers,
Micah


How to auto export JSON file after running SQL command?
How to auto export JSON file after running SQL command?
#3

Thanks @mmoore. :smiley:

@Joe_Foley The approach shown above will work, though there’s an easier way too.

In the “Execute SQL” tab, there’s a button in the bottom right for exporting the results:

That pops up a small menu, the first choice in it is for saving the results to a CSV file:

DB4S_csv_export2

DB4S_csv_export3

Note - make sure you select an appropriate “New line characters” option in that dialog, otherwise your results might end up looking like they’re all on one line.

In theory, I think that’s what you’re looking for. :slight_smile:

As a thought, if you have other questions, feedback, want to file bugs (etc), then this here is the place you want:

We’re generally pretty friendly. :slight_smile:


#4

Dear Micah & Justin:
THANK YOU.
I sam finally able to save my DB Browser results.
FANTASTIC.
I wish they would move that button from the bottom right to the upper
left. Those who know what they are doing will find it but those of us lost
in the woods would not think to look away from all of the drop down menus.

So if you guys ever need a kidney or a lung or a pint of blood, just ask.
I’d offer you the brain but its not good for much.

HAVE A GREAT DAY.


#5

Ahhh, good point. I’m so used to it in the bottom right that I’ve never really thought about it.

Just added an item about that to our issue tracker:

https://github.com/sqlitebrowser/sqlitebrowser/issues/1122

No idea how it’ll go (I can see both pro’s and cons to moving it), but at least it’s on the radar now. :slight_smile:


#6

Good news Joe. That button has now been moved. The change isn’t in our just-released-today version 3.10.1. But it is in our nightly builds, and will be in the official 3.11.0 release (when that comes out). :smile: