0 votes
1 view
in Java by (12.7k 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...