Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8172699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:52:12+00:00 2026-06-06T21:52:12+00:00

i have a sqlite3 database that has multiple (six) tables and i need it

  • 0

i have a sqlite3 database that has multiple (six) tables and i need it to be imported to csv, but when i try to import it, i get a duplicated value if a column (in a table) is larger than another (in another table).

ie: this is how my sqlite3 database file looks like:

column on table1     column on table2   column on table3
25                   30                 20
30

this is the result on the .csv file (using this script as example)

25,30,20
30,30,20

and this is the result i need it to show:

25,30,20
30

EDIT: Ok, this is how i add the values to each table, based on the python documentation example (executed each time a value entry is used):

import sqlite3
conn = sqlite3.connect('database.db')

c = conn.cursor()

# Create table
c.execute('''CREATE TABLE table
            (column int)''')

# Insert a row of data
c.execute("INSERT INTO table VALUES (value)")

# Save (commit) the changes
conn.commit()

# We can also close the cursor if we are done with it
c.close()

any help?

-Regards…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:52:14+00:00Added an answer on June 6, 2026 at 9:52 pm

    This is how you could do this.

    import sqlite3
    
    con = sqlite3.connect('database')
    cur = con.Cursor()
    
    cur.execute('select table1.column, table2.column, table3.column from table1, table2, table3')
    # result should look like ((25, 30, 20), (30,)), if I remember correctly
    results = cur.fetchall()
    
    output = '\n'.join(','.join(str(i) for i in line) for line in results)
    

    Note: this code is untested, written out of my head, but I hope you get the idea.


    UPDATE: apparently I made some mistakes in the script and somehow sql ‘magically’ pads the result (you might have guessed now that I’m not a sql guru :D). Another way to do it would be:

    import sqlite3
    conn = sqlite3.connect('database.db')
    
    cur = conn.cursor()
    
    tables = ('table1', 'table2', 'table3')
    results = [list(cur.execute('select column from %s' % table)) for table in tables]
    
    def try_list(lst, i):
        try:
            return lst[i]
        except IndexError:
            return ('',)
    
    maxlen = max(len(i) for i in results)
    results2 = [[try_list(line, i) for line in results] for i in xrange(maxlen)]
    
    output = '\n'.join(','.join(str(i[0]) for i in line) for line in results2)
    print output
    

    which produces

    25,30,20
    30,,
    

    This is probably an overcomplicated way to do it, but it is 0:30 right now for me, so I’m not on my best…
    At least it gets the desired result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Content Provider for a SQLite database that has multiple tables and
i have sqlite3 database file, that is back-end of a blog. The blog has
I have a Sinatra DataMapper app hitting a sqlite3 database that I am attempting
I have an app that must get data from the Sqlite database in order
My database (sqlite3), has two tables with the following schemas: CREATE TABLE log(d date,
I have a Sqlite database that has a table consisting of company information (Companies)
I have an iPhone application that uses a sqlite3 database for saving data and
I want to have an application that has a permanent database file(on a hard
My application has multiple SQLite tables(around 20 with different fields). This I have created
I have a SQlite3 table that has typeless columns like in this example: CREATE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.