473,386 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

sqlite3 - SQL question regarding update of a table based on lookup table

1
I have a table AVI with the following relevant structure:
POLY_NUM key
LKP
SITE1
SITE2
SITE3
Y2BH

I have a lookup table SILKP with:
LKP
SITE1
SITE2
SITE3
Y2BH

what is the fastest/most efficient way to update table A SITE1-SITE3 and Y2BH fields by linking via lookup.

What I have:

Expand|Select|Wrap|Line Numbers
  1. with sqlite3.connect(db_filename) as conn:
  2.     cursor = conn.cursor()
  3.  
  4.     print "Updating lookup fields..."
  5.  
  6.     cursor.execute("""
  7.                         UPDATE avi SET site1 = (SELECT site1 FROM silkp WHERE silkp.lkp = avi.lkp)
  8.                    """)
  9.     cursor.execute("""
  10.                         UPDATE avi SET site2 = (SELECT site2 FROM silkp WHERE silkp.lkp = avi.lkp)
  11.                    """)
  12.     cursor.execute("""
  13.                         UPDATE avi SET site3 = (SELECT site3 FROM silkp WHERE silkp.lkp = avi.lkp)
  14.                    """)
  15.                         UPDATE avi SET y2bh = (SELECT y2bh FROM silkp WHERE silkp.lkp = avi.lkp)
  16.                    """)
Is there a faster and more elegant way?
Feb 6 '13 #1
1 2119
Rabbit
12,516 Expert Mod 8TB
You can try joining the tables and updating it in one statement. This works in SQL Server, you can see if it works in SQLite.
Expand|Select|Wrap|Line Numbers
  1. UPDATE t1
  2. SET field1 = t2.field1,
  3.     field2 = t2.field2
  4. FROM t1 INNER JOIN 
  5.      t2 ON t1.id = t2.id
Feb 6 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Art at ABE Computer Consultants | last post by:
I'm missing something really simple, I'm sure. I have a form to be filled in. The operator choosed a plant species (the botanical name) from a list in a combo box. (The lookup table is populated...
4
by: Paul | last post by:
Hi, When should I use a list (in table properties: like Ford;Mercedes;BMW;Audi ) and when should I use a lookup table?? And second question: IF I use a lookup table, should I always make a...
1
by: James | last post by:
I am used to VB6 but need to develop something in .Net. I need to create several bound combo-boxes which will use lookup tables to get their values. I created a form using the dataform wizard....
3
by: dbuchanan | last post by:
Hello, (Windows forms - SQL Server) I fill my datagrid with a stored procedure that includes relationships to lookup tables so that users can see the values of the combobox selections rather...
11
by: Paul H | last post by:
Suppose I have a table called tblPeople and I want a field to illustrate whether each person prefers cats or dogs. I could do it one of three ways. 1. A plain text field Create a text field in...
5
by: sensreview | last post by:
Hello, I need help in selecting a value from combo list thru one lookup table and update different table on MS access form. For eg; I have a lookup table of usernames, I need to use this...
5
by: Andrus | last post by:
I'm creating a database Winforms application using VCS Express 2005 I have some large lookup tables (may be up to 500000 records) which contains name and id and are stored in sql server. I...
2
by: JHNielson | last post by:
I am trying to see is there is a way to lookup and update a field based on matching part of the contents of a field to a lookup table. Example. I have an "Error Description" field. And it adds...
1
by: paulquinlan100 | last post by:
Hi Im having problems getting a column in one of my tables to display the lookup values correctly. The database is split, in the backend the rowsource for this particular field is set to a...
0
by: =?Utf-8?B?RU1hbm5pbmc=?= | last post by:
(I originally posted this to the data access newsgroup but received no replies) I've got an Access 2003 mdb that I'm converting to VB.Net. I'm having trouble with getting the main data source to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.