Save query results as csv

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

@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

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:

DB4S_csv_export1

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:

1 Like

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.

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:

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:

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:

2 Likes

Guys, thank you sooooo much! I’ve been struggling for an hour until I found your answer. That’s awesome and answsers perfectly my questions. If I may, I would only have one more question. I am based in France and when I do the csv export from DB Browser, I get wrong characters displayed on the csv. If anyone has an idea how I could fixed that… thank you again, so much!

Hi @Benjamin_Labarthe-Pi

If you wish to report an issue regarding the behavior within DB Browser for SQLite, that would be best directed to their GitHub Issues page here. Zetetic does not develop or maintain DB Browser for SQLite, rather we develop both SQLCipher and Codebook. If you are experiencing an issue specific to SQLCipher, please feel free to post that separately here. Thanks!

that’s noted! thanks again