Using SQlite

Hello, currently taking the data analyst course on Python and they provided us with this code in the tuto but i don’t understand the 2nd line with the query. I’ve never seen this syntax with the " || ’ ’ || " and “WHERE id=?”. What does it do. I also don’t understand why in the cursor.execute(query, [person_id]). person_id has to be in brackets. Third question: I googled the difference between MySQL and SQLite3 and I didn’t concretely understand the difference when do you choose one over the other. Thank you!

``` def get_name(database_file, person_id): query = "SELECT personal || ' ' || family FROM Person WHERE id=?;" connection = sqlite3.connect(database_file) cursor = connection.cursor() cursor.execute(query, [person_id]) results = cursor.fetchall() cursor.close() connection.close() return results[0][0] ```

Hello @object0210195723 ,

Can you include a link to the lesson please?

Usually the ‘||’ pipe symbols are used for concatenating values together and the “WHERE id=?” will be translated to WHERE id = person_id when the query is executed in the cursor.

I hope that helps.

1 Like

Hello @object0210195723 ,

Here is a nice summary on the differences:
What to Use – SQLite or MySQL? In-Depth Analysis For Your Convenience (hostinger.com)