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 7716881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:44:36+00:00 2026-06-01T02:44:36+00:00

I seem to find many tutorials on how to work with two table, but

  • 0

I seem to find many tutorials on how to work with two table, but I can’t seem to figure out how to create two tables. I am probably missing something very simple.

I want to create a table for my_data_1 and my_data_2. Here is my code:

import sqlite3

my_data_1 = [('a',1,'BUY'),('b',2,'SELL'),('c',3,'HOLD')]

my_data_2 = [('a',1,5),('d',6,6),('e',2,7)]

 #I am using :memory: because I want to experiment
 #with the database a lot

conn = sqlite3.connect(':memory:') 

c = conn.cursor()

c.execute('''CREATE TABLE MY_TABLE_1
          (stock TEXT, price REAL, recommendation TEXT )''' )

### Something is probably wrong with the following line

c.execute('''CREATE TABLE MY_TABLE_2
          (stock TEXT, price REAL, volume REAL )''' )



for ele in my_data_1:
    c.execute('''INSERT INTO MY_TABLE_1 VALUES(?,?,?)''',ele)

conn.commit()

c.execute('SELECT* FROM MY_TABLE_1')

for entry in c:
    print entry

c.execute('SELECT* FROM MY_TABLE_2')

for entry in c:
    print entry

My output is:

(u'a', 1.0, u'BUY')
(u'b', 2.0, u'SELL')
(u'c', 3.0, u'HOLD')

So I have not created MY_TABLE_2. How should I do this?

Thank You in Advance.

  • 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-01T02:44:37+00:00Added an answer on June 1, 2026 at 2:44 am

    You aren’t inserting anything into Table 2

    Try this code after you insert into Table 1.

    for ele in my_data_2:
        c.execute('''INSERT INTO MY_TABLE_2 VALUES(?,?,?)''',ele)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen many questions like this, but i can't seem to find the answer:
I know there are many other questions out there, but I can't seem to
I know many of these questions exist but I can't seem to find one
I've looked around many different places, but can't seem to find a straighforward way
A product like Resharper has many settings, and I can't seem to find the
I've skimmed thru Date and Silberschatz but can't seem to find answers to these
I am trying to do something really basic but can not seem to find
I have two strings that I need to pull data out of but can't
I can't seem to find details on how to unsubscribe from ubiquity commands. The
I can't seem to find that option. Surely it's in there?

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.