Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
546 views
in Data Manipulation Through SQL by (49.1k points)
closed by

Considers the following tables appointments and students and write the python script to display the following output?

Rollno Sname Duty Age
1 Akshay Prefect 17
2 Aravind Secretary 16

1 Answer

+1 vote
by (54.8k points)
selected by
 
Best answer

Given:

Student → Table Rollno, Sname, grade, gender, average, birth-date

Appointment → rollno, duty, age

Example

import sqlite3

connection = sqlite3.connect(“Academy.db”) cursor = connection.cursor( )

cursor.execute(“””DROP TABLE Appointment;”””) sql_command = “””

CREATE TABLE Appointment(rollnointprimarkey,Dutyvarchar(10),age int)”””

cursor.execute(sqlcommand)

sql command – ‘””INSERT INTO Appointment (Rollno,Duty ,age)

VALUES (“1” , “Prefect” , “17”);”””

cursor, execute(sql_command)

sql_command = ”””INSERT INTO Appointment (Rollno,Duty, age)

VALUES (“2” , “Secretary” , “16”);””” 

cursor.execute(sql_command)

# never forget this, if you want the changes to be saved:

connection.commit( )

cursor.execute(“SELECT student.rollno,student.sname,Appointment. 

Duty,Appointment.Age FROM student,Appointment where student.

rollno= Appointment.rollno”)

#print (cursor.description) to display the field names of the table

co= [i[0] for i in cursor.description] print(co)

# Field informations can be readfrom cursor.description.

result = cursor. fetchall( )

for r in result:

print(r)

OUTPUT

[‘Rollno’, ‘Sname’ , ‘Duty’ , ‘age’]

(1, ‘Akshay’ , ‘Prefect’ , 17)

(2, ’Aravind’ , ’Secretary’ , 16)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...