I'm trying to update a flag in a phone number table
isbest : must be mobile and priority shoud be the closest to 0
cpf is FOREIGN KEY, so one id can have multiple phones, but only one will receive 'isbest' flag
UPDATE telefone SET isbest = 1 WHERE fullnumber in (SELECT fullnumber,min(priority)
FROM telefone
WHERE phonetype = "MOBILE"
GROUP BY telefone.cpf
)
But I get this error:
sub-select returns 2 columns - expected 1
i've changet my code to
UPDATE telefone SET isbest = 1 WHERE fullnumber in (SELECT fullnumber
FROM telefone
WHERE phonetype = "MOBILE"
GROUP BY telefone.cpf
ORDER BY priority asc
)
But then it update more numbers than expected (but the Subquery when run alone shows the right rows)
On the first code, I've tried to add another Subquery (select fullnumber from (...) ) but it also didn't help (Again, the subquery alone looks right)
i'm using SQLITE3 with SQLiteStudio
TL;DR when the code runs, at affects more rows than expected, but the subquery alone looks right