kevinUsa Posted March 4, 2020 Report Posted March 4, 2020 import sqlite3 conn = sqlite3.connect('aaa.sqlite') cur = conn.cursor() cur.execute('DROP TABLE IF EXISTS Student') cur.execute('DROP TABLE IF EXISTS Courses') cur.execute('CREATE TABLE Student(name TEXT, Student_id INTEGER, course_id INTEGER)') cur.execute('CREATE TABLE Courses (course_id INTEGER, Course_name TEXT)') cur.execute('INSERT INTO Student (name, Student_id, course_id ) VALUES (?,?,?)', ( 'TOm', '20044844', '12345' )) cur.execute('INSERT INTO Courses (course_id ,Course_name) VALUES (?,?)', ( '12345','maths' )) cur.execute('SELECT name, Student_id FROM Student') print('Student') print('Courses') conn.commit() Quote
kevinUsa Posted March 4, 2020 Author Report Posted March 4, 2020 can anyone let me know the mistake in thsi Quote
kevinUsa Posted March 4, 2020 Author Report Posted March 4, 2020 I created a table than manually inserted the values but when I try to print the table I am getting name of the table but not the values in the table Quote
kevinUsa Posted March 4, 2020 Author Report Posted March 4, 2020 1 minute ago, r2d2 said: Courses table select missing? i want ot print values from student table only just started to learn python Quote
Spartan Posted March 4, 2020 Report Posted March 4, 2020 Just now, kevinUsa said: I created a table than manually inserted the values but when I try to print the table I am getting name of the table but not the values in the table cur.execute('SELECT course_name, Course_id FROM Courses') Quote
kevinUsa Posted March 4, 2020 Author Report Posted March 4, 2020 Just now, Spartan said: cur.execute('SELECT course_name, Course_id FROM Courses') can you run on this let me me know what results Quote
kevinUsa Posted March 4, 2020 Author Report Posted March 4, 2020 1 minute ago, Spartan said: cur.execute('SELECT course_name, Course_id FROM Courses') import sqlite3 conn = sqlite3.connect('assingnment.sqlite') cur = conn.cursor() cur.execute('DROP TABLE IF EXISTS Student') cur.execute('DROP TABLE IF EXISTS Courses') cur.execute('CREATE TABLE Student(name TEXT, Student_id INTEGER, course_id INTEGER)') cur.execute('CREATE TABLE Courses (course_id INTEGER, Course_name TEXT)') cur.execute('INSERT INTO Student (name, Student_id, course_id ) VALUES (?,?,?)', ( 'TOm', '20044844', '12345' )), cur.execute('INSERT INTO Student (name, Student_id, course_id ) VALUES (?,?,?)', ( 'TOm', '20044842', '12345' )), cur.execute('INSERT INTO Student (name, Student_id, course_id ) VALUES (?,?,?)', ( 'TOm', '20044843', '12345' )), cur.execute('INSERT INTO Student (name, Student_id, course_id ) VALUES (?,?,?)', ( 'TOm', '200448442', '12345' )) cur.execute('INSERT INTO Courses (course_id ,Course_name) VALUES (?,?)', ( '12345','maths' )), cur.execute('SELECT name, Student_id FROM Student') cur.execute('SELECT course_name, Course_id FROM Courses') print('Student') print('Courses') Quote
Spartan Posted March 4, 2020 Report Posted March 4, 2020 1 minute ago, kevinUsa said: can you run on this let me me know what results it will result, but not exactly what u r looking for.. u might want to try inner join...its not python issue, its sql query issue.. calling sql experts. select column1 from table1 inner join table2 on table1.column = table2.column where table2.columne=0 Quote
kevinUsa Posted March 4, 2020 Author Report Posted March 4, 2020 Just now, Spartan said: it will result, but not exactly what u r looking for.. u might want to try inner join...its not python issue, its sql query issue.. calling sql experts. sql statement is correct I want just print the contents in students table when i try to do it I am getting the name of the table but not the contents of the table Quote
Popular Post cosmopolitan Posted March 4, 2020 Popular Post Report Posted March 4, 2020 import sqlite3 conn = sqlite3.connect('aaa.sqlite') cur = conn.cursor() cur.execute('DROP TABLE IF EXISTS Student') cur.execute('DROP TABLE IF EXISTS Courses') cur.execute('CREATE TABLE Student(name TEXT, Student_id INTEGER, course_id INTEGER)') cur.execute('CREATE TABLE Courses (course_id INTEGER, Course_name TEXT)') cur.execute('INSERT INTO Student (name, Student_id, course_id ) VALUES (?,?,?)', ( 'TOm', '20044844', '12345' )) cur.execute('INSERT INTO Courses (course_id ,Course_name) VALUES (?,?)', ( '12345','maths' )) student_obj=cur.execute('SELECT name, Student_id FROM Student').fetchall() course_obj=cur.execute('SELECT course_id, Course_name FROM Courses').fetchall() print(student_obj) print(course_obj) 2 2 Quote
kevinUsa Posted March 4, 2020 Author Report Posted March 4, 2020 1 minute ago, cosmopolitan said: import sqlite3 conn = sqlite3.connect('aaa.sqlite') cur = conn.cursor() cur.execute('DROP TABLE IF EXISTS Student') cur.execute('DROP TABLE IF EXISTS Courses') cur.execute('CREATE TABLE Student(name TEXT, Student_id INTEGER, course_id INTEGER)') cur.execute('CREATE TABLE Courses (course_id INTEGER, Course_name TEXT)') cur.execute('INSERT INTO Student (name, Student_id, course_id ) VALUES (?,?,?)', ( 'TOm', '20044844', '12345' )) cur.execute('INSERT INTO Courses (course_id ,Course_name) VALUES (?,?)', ( '12345','maths' )) student_obj=cur.execute('SELECT name, Student_id FROM Student').fetchall() course_obj=cur.execute('SELECT course_id, Course_name FROM Courses').fetchall() print(student_obj) print(course_obj) got it thanks Quote
cosmopolitan Posted March 4, 2020 Report Posted March 4, 2020 4 minutes ago, kevinUsa said: sql statement is correct I want just print the contents in students table when i try to do it I am getting the name of the table but not the contents of the table python lo print tharvatha qotes lo unte.. it just prints whatever is in quotes.. unless you give input using {} and format. ex: a=2 print('a') print('a = {}'.format(a)) output : a a =2 Quote
kevinUsa Posted March 4, 2020 Author Report Posted March 4, 2020 Just now, cosmopolitan said: python lo print tharvatha qotes lo unte.. it just prints whatever is in quotes ex: a=2 print('a') print('a = {}'.format(a)) output : a a =2 got it bro fetchall() y using here Quote
MeetFriendz Posted March 4, 2020 Report Posted March 4, 2020 7 minutes ago, kevinUsa said: sql statement is correct I want just print the contents in students table when i try to do it I am getting the name of the table but not the contents of the table print(table) ('Student') try this .. naku python radhu just google chesa first linke lo vunde .. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.