473,412 Members | 2,051 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,412 software developers and data experts.

sqlite insert question

131 128KB
If this is the wrong forum, please forgive me - I didn't see an sqlite category.

I've got two somewhat related tables.

Expand|Select|Wrap|Line Numbers
  1. tbl_main
  2.    id integer primary key autoincrement
  3.    volume text unqiue not null default ''
  4.    note text not null default ''
  5.  
  6. tbl_media
  7.    id integer primary key autoincrement
  8.    volume_key text not null default ''
  9.    fname text not null default ''
  10.    fsize text not null default ''
  11.    fdate text not null default ''
  12.    ftype text not null default ''
  13.    fduration text not null default ''
  14.    frame text not null default ''
  15.  
the first table's fields are for a disc volume label and a user entered description for the disc.

the second table identifies the entries by the volume_key.

my question is, can I insert new entries by selecting where a stored fname doesn't exist?

An example of what I'm asking is adding files from a flash drive to the database. I then add new files to the flash drive and want to update the database with only the newly added files.

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tbl_media VALUES(...) WHERE SELECT FROM tbl_media fname != 'newly added file'
  2.  
Something like that. Is that possible? If so, what is the proper syntax?

TIA
Jul 7 '13 #1
3 1722
Rabbit
12,516 Expert Mod 8TB
That doesn't make any sense, why would you want to insert into the table by selecting records from the table? You just end up duplicating data that you already have.

Now if what you actually want to do is merge two DIFFERENT tables by selecting the records that exist in one that doesn't exist in the other, then you need to use an outer join query.

When you outer join two queries and return just the ones where the fields that are joined are null, that gives you the non matches. For example:
Expand|Select|Wrap|Line Numbers
  1. SELECT t1.*
  2. FROM oldTable AS t1
  3. RIGHT OUTER JOIN newTable AS t2
  4. ON t1.keyField = t2.keyField
  5. WHERE t1.keyField IS NULL
Jul 7 '13 #2
divideby0
131 128KB
Rabbit, thank you for your time.

Basically, I'm trying to centralize my collection of data cdroms / dvds, tape backups, hard drives, etc. dating back to the 90s.

Each drive / disc / tape is a record identifed by its volume label with any number of files. I can filter the contents before adding them to the database, which could exclude some data. Later, if I decide to add the excluded files, I can rescan the device, which lists all files on the device. With so many records, I cannot recall what's been added or filtered out.

That's where the problem lies; I don't want to add existing entries... only items that may have been excluded at the time the record was originally created.

I'm not verse in SQL, but basically, if some_file doesn't exist in the record identified by volume_key, then add some_file to the record identified by volume_key.

I remember getting help several years ago with something similar using php and mysql, but I cannot recall how it was it done... maybe use count() on the SELECT or something.

The only alternative that I can think of is to query for the name first, and then insert, but I was hoping for a way to do it using one operation.
Jul 7 '13 #3
Rabbit
12,516 Expert Mod 8TB
Yes, I know. That's what the solution I outlined earlier will do.
Jul 8 '13 #4

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

Similar topics

5
by: TThai | last post by:
HI, I'm trying to insert records to a table using bcp command. The problem is the input file to the bcp is a text file that looks like this: Text file data: 1234 abc def ghi jkl mno ...
1
by: Mattias B | last post by:
Hello! I have a question about how stl's insert works on containers and on vector in particular. The question is: is it OK to insert a value before end() with something like: vector<int>...
20
by: akej via SQLMonster.com | last post by:
Hi, i have table with 15 columns CREATE TABLE . ( PRIMARY KEY , NULL , NULL , NULL , NULL , (50) NULL , NULL
11
by: Jean-Christian Imbeault | last post by:
I have a table with a primary field and a few other fields. What is the fastest way to do an insert into that table assuming that sometimes I might try to insert a record with a duplicate primary...
2
by: Daniel Tan | last post by:
I got a syntax error in SQL insert into statement , hope someone can help me .Thanks. job_search = "='" & Me.Jobno & "' " sqlstr = "INSERT INTO Custorder (job_order) " & _ "values " &...
4
by: ams | last post by:
I set up a database of civic league members and residences. I set the primary key to conform to addresses by street numbers. Unfortunately, I omitted two buildings. How do I insert the data for...
2
by: Russ Schneider | last post by:
I downloaded the port for Postgres for PHP-NUKE. All insert statements are as follows: For table: Table "nuke_referer" Column | Type | Modifiers...
9
by: David Eades | last post by:
Hi all Complete newbie here, so apologies if this is the wrong forum. I've been asked to use mysql and asp to make a simple bidding system (rather like a simple ebay), whereby users can use a...
2
josie23
by: josie23 | last post by:
Egad, I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile. But, I've been trying to...
1
by: PrakashRS | last post by:
Given the table T1, created by: CREATE TABLE t1 (id INTEGER GENERATED BY DEFAULT AS IDENTITY, c1 CHAR(3) ) The following SQL statements are issued: INSERT INTO t1 VALUES (1, 'ABC') INSERT INTO...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.