-2

Sorry if this question is dumb. i am a beginner and for the past hour i'v been searching the internet for answer and i haven't found one(maybe because i am bad at searching). Anyway, i am writing a query into python so i have to write the entire query into one line but i can't seem to get it right.

SELECT students.first, students.middle, students.last, students.birth
FROM students
WHERE students.house = "Gryffindor"
ORDER BY students.last ASC, students.first ASC
  • Are you just trying to delimit your quotes? If so see this link https://stackoverflow.com/questions/897020/a-good-way-to-escape-quotes-in-a-database-query-string – Johnny Fitz Jan 22 '21 at 19:23
  • 2
    You can create a multiline string: https://stackoverflow.com/a/10660443/10498828 – forpas Jan 22 '21 at 19:26

1 Answers1

0

Here are two methods:

'''SELECT students.first, students.middle, students.last, students.birth
FROM students
WHERE students.house = "Gryffindor"
ORDER BY students.last ASC, students.first ASC'''

"SELECT s.first, s.middle, s.last, s.birth FROM students s WHERE s.house = 'Gryffindor' ORDER BY s.last ASC, s.first ASC"

The firsts uses multi-line strings. The second shortens the query a bit, uses single quotes for the embedded string (the SQL standard delimiter), and puts everything on one line.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786