Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
How to Copy Table to Another Table in SQL
Next article icon

How to Update a Table Data From Another Table in SQLite

Last Updated : 02 Feb, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

SQLite is an embedded database that doesn't use a database like Oracle in the background to operate. The SQLite offers some features which are that it is a serverless architecture, quick, self-contained, reliable, full-featured SQL database engine. SQLite does not require any server to perform queries and operations on the database.

In this article, we will see the stepwise implementation of how we can update a table with the data from another table in SQLite.

Introduction to UPDATE Statement in SQLite

UPDATE command is used to alter to change the content of the table. Updating a table using the Data from another table becomes important when there is a mistake present in the previous table. The mistake can be minor or it can be major, due to this a temporary and separate table can be made and all the data from Table One can be moved to Table Two.

Stepwise Implementation

Before understanding the implementation process, it is recommended to create and populate a table in SQLite. For this tutorial, we will be using a table called students and populate it with values. Write and execute the following.

Query:

CREATE TABLE Students 
(
Student_ID INTEGER,
FirstName TEXT,
LastName TEXT,
Class INTEGER,
Section TEXT
);

Explanation: After creation of the table. Now we will insert some records into the Students table.

Query:

INSERT INTO Students VALUES(10,'Vivek','Singh',7,'B');
INSERT INTO Students VALUES(12,'Manish','Roy',8,'A');
INSERT INTO Students VALUES(15,'Dilip','Mukherjee',10,'A');
INSERT INTO Students VALUES(16,'Souvik','Sen',10,'B');
INSERT INTO Students VALUES(18,'Rohit','Das',10,'A');
INSERT INTO Students VALUES(21,'Mohit','Shetty',9,'A');
INSERT INTO Students VALUES(22,'Raj','Banerjee',9,'B');
INSERT INTO Students VALUES(24,'Biswajit','Das',7,'B');
INSERT INTO Students VALUES(25,'Srijit','Roy',8,'A');
INSERT INTO Students VALUES(27,'Rakesh','Chatterjee',8,'C');

Now we will see the stepwise implementation of How we can Update another Table Using the Values of this Table.

Step 1: Create Another Table With Different Name

Firstly, we will create another table with a name which is different than our already existing table. User can choose names which might resemble to the table or completely different. Write and execute the following command to create the second table.

Query:

CREATE TABLE Temp_Students 
(
Student_ID INTEGER,
FirstName TEXT,
Class INTEGER
);

Explanation: Here, the table Temp_Student is being created which has some common columns with the main Students table. Now we will update this table with the help of data from the Students table.

Step 2: Fetch Data Exist in Both Table

Now, we will fetch the data from the columns of Students table which is common with the second table. We will use the INSERT INTO command and pass the Table name and the columns of the second table. Then using the SELECT statement we will fetch the values of those respective common columns from the Students table.

Query:

INSERT INTO Temp_Students 
(
Student_ID, FirstName, Class
)
SELECT Student_ID, FirstName, Class FROM Students;

Step 3: Show All Content of Second Table

Now we will use the SELECT statement to print the entire content of the Temp_Students table and check if the values are being fetched properly or not.

Query:

SELECT * FROM temp_students;

Output:

studentsOutput
Output

Explanation: As we can see, all the respective data from the Students table has been added into the Temp_Students table.

Conclusion

As we saw in this article, how we can update a table with the data from another table in SQLite. Updating a table using the data of another table becomes necessary when the developer wants to keep some part of the old table into the new table. This approach will save a lot more time because without writing multiple INSERT INTO statements, only one INSERT INTO statement is enough to fetch all the data from the previous table.


Next Article
How to Copy Table to Another Table in SQL
author
dwaipayan_bandyopadhyay
Improve
Article Tags :
  • Geeks Premier League
  • SQLite
  • Databases
  • Geeks Premier League 2023
  • SQLite Query

Similar Reads

  • How to Copy Table to Another Table in SQL
    Copying data from one table to another is a common task in SQL whether we are migrating data by creating backups or simply duplicating a table's structure and content for further use. In this article, we'll explore several ways to copy a table to another table in SQL Server including copying both th
    4 min read
  • How to Update From One Table to Another Based on an ID Match in SQL
    In SQL, updating data between tables is a common operation used to maintain data consistency and accuracy across related datasets. Whether we need to synchronize records, update fields, or correct discrepancies, SQL provides efficient methods to achieve this. In this article, we will explain how to
    4 min read
  • SQL Server Update From One Table to Another Based on an ID Match
    In the world of database management, we need to perform various OLTP operations like insert, update, and delete. The ability to efficiently update data between tables is crucial for maintaining data integrity and ensuring accurate information. SQL Server provides powerful tools to accomplish this ta
    7 min read
  • How to Update Records in Table from CTE in SQL
    Common Table Expressions (CTEs) in SQL is an important feature that provides a temporary result set that can be referred to within a SELECT, INSERT, UPDATE, or DELETE statement. In this article, we will learn how to use CTEs to update records in SQL along with examples along with an explanation. Wha
    4 min read
  • How to Copy Data From One Column to Another in the Same Table in SQL?
    Efficiency in data manipulation is crucial while using Structured Query Language (SQL). To manage a wide range of tasks, including organizing, retrieving, updating, and deleting data, SQL provides a comprehensive set of instructions. Among these, copying data between columns in the same table is a c
    4 min read
  • How to Update a Column in a Table in SQL Server
    In the database management area, updating columns in a table is a normal query and it is important software that ensures the accuracy and integrity of data. Whether we are making spelling corrections, editing or altering existing information, or being attentive to changing requirements, carrying out
    4 min read
  • How to Copy Rows from One Table to Another in SQL?
    In SQL, copying rows from one table to another is a common operation that simplifies data migration and duplication tasks. Whether creating backup tables, transferring data for analysis, or setting up a new schema, the ability to efficiently replicate data across tables is invaluable. This operation
    3 min read
  • How to Find Records From One Table Which Don't Exist in Another SQLite?
    In database management, one of the most common tasks is to compare records either to identify differences or missing records in certain tables. This phase is crucial for data validation, reconciliation, and complete data integrity. On SQLite, a lightweight relational database management system, this
    4 min read
  • How to list the Tables in a SQLite Database File ?
    SQLite is a database engine which is written in C programming language. SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is
    4 min read
  • How to Update Data in MySQL Database Table Using PHP?
    Updating data in a MySQL database table using PHP is a fundamental aspect of web development, particularly in applications where user interactions involve modifying existing records. This guide delves into the process of updating data in a MySQL database table using PHP, covering database connection
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences