I have two tables called "decks" and "notes"
I tried to SELECT table like this:
SELECT id,
title,COUNT(SELECT lastStatus FROM notes WHERE deckId=id and lastStatus='good') AS goodNotes
FROM decks
but I got this error:
sqlite3_prepare_v2 failure: near "SELECT": syntax error
CodePudding user response:
If you are using MySQL
, you can use below sql:
SELECT d.id,d.title,COUNT(n.lastStatus) AS goodNotes
FROM decks d
join notes n ON n.deckId=d.id and n.lastStatus='good'
GROUP BY d.id,t.title