Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (16.4k points)

Consider the below list:

l=[1,5,8]

I need to compose a SQL question to get the information for every one of the components of the rundown/list, say

select name from students where id = |IN THE LIST l|

How do I complete this?

1 Answer

0 votes
by (26.4k points)

The Answers till now have been templating the values/qualities into a plain SQL string. That is totally fine for numbers, yet in the event that we needed to do it for strings, we get the getting away from the issue. 

Here's a variation utilizing a defined inquiry that would work for both:

placeholder= '?' # For SQLite. See DBAPI paramstyle.

placeholders= ', '.join(placeholder for unused in l)

query= 'SELECT name FROM students WHERE id IN (%s)' % placeholders

cursor.execute(query, l)

Want to learn python to get expertise in the concepts of python? Join python certification course and get certified

Browse Categories

...