Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

find duplicate row in python sqlite database

for name in ('AlixaProDev','Salamn'): 
    cursor.execute("SELECT rowid FROM Student WHERE Name = ?", (name,))
    db_result=cursor.fetchall()
    if len(db_result)==0:
        print('There is no Student named %s'%name)
    else:
        print('Student %s found with rowids %s'%(name,','.join(map(str, next(zip(*db_result))))))Copy Code
Comment

python code to find duplicate row in sqlite database

import sqlite3
# it will create a databse with name sqlite.db
connection= sqlite3.connect('sqlite.db') 
cursor= connection.cursor()
table_query = '''CREATE TABLE  if not Exists Student
               (Name text, Course text, Age real)'''
       

cursor.execute(table_query)        
# student list 

students_data = [
 ['AlixaProDev','CS',19],
 ['Alixawebdev','BBa',21],
  ['AskALixa','Software',22],
  ['AskALixa','Software',22]
]
insert_q = []

# creating the insert query for each student
for std_data in students_data:
    name = std_data[0]
    course = std_data[1]
    age = std_data[2]
    q=f"INSERT INTO Student VALUES ('{name}','{course}','{age}')"
    # check if a row is already exist 
    cursor.execute("SELECT rowid FROM Student WHERE Name = ?", (name,))
    db_result=cursor.fetchall()
    if len(db_result)==0:
        cursor.execute(q)
        print('Studnet Data inserted Successfully')
    else:
        print('Student %s found with rowids %s'%(name,','.join(map(str, next(zip(*db_result))))))
  
        
# you need to commit changes as well
connection.commit()
# you also need to close  the connection
connection.close()Copy Code
Comment

PREVIOUS NEXT
Code Example
Python :: make python standalone 
Python :: sensitivity 
Python :: k means em algorithm program in python 
Python :: Python NumPy asmatrix Function Syntax 
Python :: codeforces problem 200B 
Python :: Python NumPy stack Function Syntax 
Python :: Python NumPy column_stack Function Example with 1d array 
Python :: inverrt heatmap cmap 
Python :: Python NumPy insert Function Example Using insertion at different points 
Python :: SciPy KDTrees 
Python :: python pandas read parquet with progressbar 
Python :: __le__ 
Python :: NumPy rot90 Example Rotating Twice 
Python :: print number upto 2 decimal places in f string python 
Python :: NumPy invert Code When the input is an array 
Python :: django view - apiview decorator (urls.py config) 
Python :: # convert dictionary keys to a list 
Python :: pandas dataframe limit rows by col value 
Python :: Python range Incrementing with the range using a positive step 
Python :: unauthorized vue django rest framework 
Python :: python selectionsort 
Python :: Examples of correct code for this rule with global declaration: 
Python :: separete even and odd numbers from a list by filter in python 
Python :: Trying to set up flask with nginx and gunicorn 
Python :: jupyter lab move tabs 
Python :: flask login attemted_user cant see check_password_correction method 
Python :: ring print part of the content of a binary file 
Python :: ring Trace Library 
Python :: importing cosine from scipy 
Python :: discord rich presence python 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =