I’m trying to display genres from a “Genre” Table in SQL to my main table I found a way to do it with one item but I cannot find a way to do it with multiple genres
x
conn = sqlite3.connect("ShowInformation - Copy.db")
c = conn.cursor()
c.execute('''SELECT name, GenreName, GenreName, Synopsis, EPCount, AgeRating, Score, Studio, Popularity
FROM Genres AS g
JOIN Animes AS a
ON a.GenreID1 AND a.GenreID2 = g.ID;''')
item = c.fetchall()
print (item[0])
print (item)
I got an error from this and I don’t know how to fix it.
Advertisement
Answer
Do a LEFT JOIN
for each genre:
SELECT a.*, g1.GenreName, g2.GenreName,
FROM Animes AS a
LEFT JOIN Genres AS g1 ON a.GenreID1 = g1.ID
LEFT JOIN Genres AS g2 ON a.GenreID2 = g2.ID