Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have added LIMIT 3 in below code to display 3 results of a JOINED table. However in Python multiple lines was displayed. In SQL execution, it is fine.

Please advise what is the reason? THanks

lib = cur.execute('''SELECT Track.title, Artist.name, Album.title, Genre.name
  FROM Track JOIN Genre JOIN Album JOIN Artist
  ON Track.genre_id = Genre.ID AND Track.album_id = Album.id
  AND Album.artist_id = Artist.id
  ORDER BY Artist.name  LIMIT 3''')
for row in lib:
  print(row)

SQL

Python


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
261 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try to change it to :

 cur.execute('''SELECT Track.title, Artist.name, Album.title, Genre.name
  FROM Track JOIN Genre JOIN Album JOIN Artist
  ON Track.genre_id = Genre.ID AND Track.album_id = Album.id
  AND Album.artist_id = Artist.id
  ORDER BY Artist.name  LIMIT 3''')
lib = cur.fetchall()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...