Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To export SQL results safely, choose a client-side CSV export for a portable data file or a workbook export when spreadsheet features are required. Then control how the file is written and how Excel interprets it: identifiers such as 00123 must be imported as text, not numbers. The exact export command depends on your database and whether the file is written on the database server or your computer.

Choose CSV or an Excel workbook

Use CSV when another tool or system needs a portable, plain-text table. Use an Excel workbook when the recipient needs spreadsheet features or your database client offers direct workbook output.

Format What it carries Best fit
CSV Delimited text representing rows and fields. It does not preserve workbook formulas, formatting, multiple sheets, or explicit cell types. Data exchange with systems and tools that accept delimited text.
Excel workbook Spreadsheet-specific features may be available, depending on the export client and format. Recipients who need spreadsheet functionality. Confirm the selected client’s output capabilities before relying on a feature.

A filename ending in .csv does not by itself guarantee valid CSV, UTF-8 encoding, preserved types, or correct interpretation in Excel. For either format, confirm what the export includes and verify the result before sharing it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I export SQL query results to CSV?

First determine where the export command writes the file. A server-side export targets storage accessible to the database server and may require server permissions. A client-side export writes to a location accessible to the application running the query, which is generally the right choice for a local download. Commands and permissions vary by product and version.

#1 Best Overall
Sale
Lexar D40E 128GB Dual USB 3.2 Gen 1 Type-C Jump Drive, Champagne Silver
  • USB-C 2-in-1 storage OTG: The Lexar JumpDrive Dual Drive D40E features USB Type-A and Type-C connectors in a slim, portable form factor for easy device compatibility
  • Transfer speeds up to 100MB/s: Based on internal testing, performance may vary depending upon the host device, interface, and usage conditions. 1MB=1,000,000 bytes
  • Plug and Play: Widely compatible with USB Type-C smartphones, tablets, laptops, Macs, and traditional Type-A devices, no software installation required. The 360° swivel design allows for easy switching between connectors without the hassle of losing a cap
  • Durable & Compact: The Lexar D40E USB memory stick features a metal enclosure, withstands temperatures from 0° to 50° C (32°F to 122°F), and is lightweight at 26g with dimensions of 70.4 x 16.9 x 11.7mm
  • Security & Warranty: Securely protects files using an advanced security software solution with 256-bit AES encryption. Backed by a Lexar 3-year limited warranty

PostgreSQL: write a local CSV with psql

In psql, use the client-side copy meta-command to send query results through the database connection and write the file on the client computer:

copy (SELECT id, code, created_at FROM public.example ORDER BY id) TO 'results.csv' WITH (FORMAT CSV, HEADER, ENCODING 'UTF8')

This is a psql meta-command, not a SQL statement to submit as-is through a generic SQL editor. Adjust the query, filename, and path for your environment; follow the operating system’s path quoting rules. Confirm the syntax against the installed PostgreSQL and psql versions.

PostgreSQL CSV mode quotes values when needed, including fields with the delimiter, quote character, carriage return, or line feed. The default distinguishes a NULL from a non-NULL empty string: NULL is an unquoted empty field, while an empty string is quoted. If the file will be loaded back into a database or another system, record the chosen NULL-marker settings and ensure the receiving tool interprets them the same way.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
SANDISK 128GB Ultra Flair, USB-A Flash Drive, Up to 150MB/s Read Speeds
  • High-speed USB 3.0 performance of up to 150MB/s(1) [(1) Write to drive up to 15x faster than standard USB 2.0 drives (4MB/s); varies by drive capacity. Up to 150MB/s read speed. USB 3.0 port required. Based on internal testing; performance may be lower depending on host device, usage conditions, and other factors; 1MB=1,000,000 bytes]
  • Transfer a full-length movie in less than 30 seconds(2) [(2) Based on 1.2GB MPEG-4 video transfer with USB 3.0 host device. Results may vary based on host device, file attributes and other factors]
  • Transfer to drive up to 15 times faster than standard USB 2.0 drives(1)
  • Sleek, durable metal casing
  • Easy-to-use password protection for your private files(3) [(3)Password protection uses 128-bit AES encryption and is supported by Windows 7, Windows 8, Windows 10, and Mac OS X v10.9 plus; Software download required for Mac, visit the SanDisk SecureAccess support page]

MySQL 8.0: understand server-side output and GUI export

MySQL 8.0 documents SELECT ... INTO OUTFILE, with options for field terminators, optional enclosure, escaping, and line terminators. This writes from the database server’s perspective; the destination must meet the server’s filesystem and security constraints. It does not automatically download the file to your workstation.

For a menu-driven workflow, MySQL Workbench documents exporting SQL-editor result grids to formats including CSV and Excel XML. Check the manual for the installed Workbench version and confirm its output behavior before relying on workbook-specific features.

Other database products

Do not assume PostgreSQL’s copy or MySQL’s INTO OUTFILE works the same way in another engine. Consult that product’s documentation for its export command or client workflow, including file destination, permissions, quoting, encoding, and NULL handling.

Rank #3
2 Pack 64GB USB Flash Drive USB 2.0 Thumb Drives Jump Drive Fold Storage Memory Stick Swivel Design - Black
  • What You Get - 2 pack 64GB genuine USB 2.0 flash drives, 12-month warranty and lifetime friendly customer service
  • Great for All Ages and Purposes – the thumb drives are suitable for storing digital data for school, business or daily usage. Apply to data storage of music, photos, movies and other files
  • Easy to Use - Plug and play USB memory stick, no need to install any software. Support Windows 7 / 8 / 10 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, compatible with USB 2.0 and 1.1 ports
  • Convenient Design - 360°metal swivel cap with matt surface and ring designed zip drive can protect USB connector, avoid to leave your fingerprint and easily attach to your key chain to avoid from losing and for easy carrying
  • Brand Yourself - Brand the flash drive with your company's name and provide company's overview, policies, etc. to the newly joined employees or your customers

How do I export a query result to Excel?

If your database client offers direct Excel output, export the query result through that client and check which workbook format and features it supports. MySQL Workbench, for example, documents Excel XML as a result-grid export option; that is a client-specific capability, not a universal database command.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If the available export is CSV, open it in Excel using a controlled import rather than relying on a casual double-click. CSV is text, not a workbook: it does not retain multiple sheets, formatting, formulas, or explicit cell types. An import can also change how values are represented if Excel infers types.

Import CSV into Excel without changing identifiers or values

  1. Start the import: In Excel, go to Data > From Text/CSV and select the file.
  2. Inspect before loading: Choose Transform Data when you need to control column types. Check the encoding and parsing locale.
  3. Set sensitive columns to Text: Apply this to identifiers, product codes, long digit strings, and other values that must remain exactly as exported. A code such as 00123 is text semantically, even though it contains only digits.
  4. Set date and number interpretation deliberately: For an ambiguous date like 03/04/2025, establish whether it means March 4 or April 3, then select an appropriate locale and data type.
  5. Load and verify: Compare representative rows with the query results. Check row counts and, for sensitive extracts, key totals or known identifiers before sharing the workbook.

Microsoft documents that Excel can remove leading zeros, display long numeric strings in scientific notation, retain only 15 digits of numeric precision when interpreting values as numbers, and convert some continuous letter-and-number strings into dates. Those behaviors are why identifier-like columns should be imported as Text when their exact characters matter. Avoid adding a leading apostrophe or rewriting identifiers in the SQL output unless you intentionally want to change the exported value and have confirmed that the receiving system accepts the change.

Rank #4
SIMMAX 32GB Memory Stick USB 2.0 Flash Drives Swivel Thumb Drive Pen Drive (32GB Purple)
  • GOOD VALUE PACKAGE - 1 Pack 32GB Memory Stick USB 2.0 Flash Drives with great cost performance and high quality.
  • BIG CAPACITY - The available capacity: 29.10GB-29.8GB, You can save the data of movies, music, photos, designs, programs, manuals, handouts in a high speed.Good performance in digital data storing, transferring and sharing with families, friends, workmates, clients and machines.
  • EASY TO USE & PLUG AND WORK - Support windows 7 / 8 / 10 / Vista / XP / 2000 / ME / NT Linux and Mac OS, Compatible with USB2.0 and below.
  • TWISTTURN DESIGN & EASY CARRY - The metal clip rotates 360° round the ABS plastic body which with rubber oil skin feeling finish. The capless design can avoid lossing of cap, and providing efficient protection to the USB port.
  • WARRANTY & SUPPORT - SIMMAX logo is laser printed on the USB connector surface, our products are of good quality and we promise that any problem about the product within one year since you buy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check CSV structure, NULLs, and locale

Quoting and delimiters

CSV is structured text, not simply a query result separated by commas. A field containing the delimiter, a quote character, or a line break needs correct quoting and escaping. Use the database’s documented CSV mode or a client that produces valid delimited output; do not assume that saving text with a .csv extension handles these cases correctly.

NULL versus empty string

Export and import settings can either distinguish NULL from an empty string or make them indistinguishable. PostgreSQL’s default CSV representation distinguishes them as described above, but another export configuration or receiving application may behave differently. If round-tripping matters, specify and document the NULL representation at both ends.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Dates, numbers, and locale

Locale affects how applications parse dates and numbers. Choose the intended locale during import, then check representative values against the database output. Do not treat a successful load as proof that ambiguous dates or numeric formats were interpreted correctly.

Best Value
IMEASON Swivel Design 16GB USB Flash Drive with Keychain, USB 2.0 Portable Thumb Drive Memory Stick, FAT32 Format Flashdrive for Data Storage, Photos, Music, Files (Black, 16 GB)
  • 【16GB Flash Drive】USB flash drives with 16GB capacity, meet your needs of daily use on work, school, home and travelling for photos, music, videos, files storage and transfer. IMEASON thumb drives can be used to store different files, easy to data backup.
  • 【Metal Swivel Cap Design】USB thumb drive is metal swivel cover provides extra protection for the usb thumbdrive connector, no usb drive cap to lose; keychain design makes it easier to carry without worrying lose it.
  • 【Wide Compatibility】USB drive supports Windows 7/8/10/11 / Vista / XP / Unix / 2000 / ME / NT Linux and Mac OS, also Supports USB 2.0 and 1.1 ports. USB Stick support TV, desktop, notebook computer, car, audio and other device. The USB Memory Stick is your great data storage and transfer companion with traveling and working.
  • 【Easy to use】usb memory stick is plug and play without any software installation. Just simply plug the Flashdrive into the port of your USB-compatible devices such as computer, laptop to start data storage or transmission.
  • 【What You Get】16 GB USB Flash Drive Thumb Drive, The default format of the usb storage flash drive is FAT32.

Respect Excel worksheet limits

Microsoft documents a maximum of 1,048,576 rows and 16,384 columns for Excel text import and export. These are product limits; the cited Microsoft support page does not state a publication year. A worksheet cannot display more than 1,048,576 rows. Some Power Query workflows can process data beyond worksheet capacity, but that does not raise the worksheet limit. For larger extracts, use another destination or deliberately split or transform the data rather than expecting one worksheet to contain it all.

Final checks before handing off an export

  • Confirm whether the file was written on the server or on the client, and that its destination and access permissions are appropriate.
  • Verify the selected query, row count, column count, encoding, delimiter, quoting, and NULL representation.
  • Import identifier-like columns as Text and validate dates and numbers using the intended locale.
  • Compare sample rows and, where accuracy is critical, key totals or known identifiers with the database results.
  • Choose a non-worksheet destination or an intentional split if the extract exceeds Excel’s worksheet capacity.

Sources: PostgreSQL COPY documentation; MySQL 8.0 SELECT … INTO documentation; MySQL Workbench export and import documentation; Microsoft guidance on leading zeros and large numbers; Microsoft Excel specifications and limits.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.