0
Dear, I have two tables (A and B), in which B has a foreign key of A. Example:
A(id, campo1, campo2)
B(id, idA, campo3, campo4)
I need to count the amount of B.idA
and thereby define a true
or false
to update the campo2
of A. I thought of two ways (but none of them worked):
UPDATE A INNER JOIN B ON A.id = B.idA SET A.campo2 = IIF(Count(B.idA) = 1, FALSE, TRUE);
and
UPDATE A SET A.campo2 = (SELECT IIF(Count(*) = 1, FALSE, TRUE) AS Nome FROM B WHERE B.idA >= 1 GROUP BY B.idA);
I don’t know if every BDS has that clause IIF
, I’m using Msaccess. She’s like a ternary parole.
What’s the right way to do this UPDATE
?
The first way, I can’t even say if it exists, the second would be as close as possible, if you want something similar to an IIF in the query, try to use the case when.
– Daniel Mendes
Actually, the first way does not work... I managed to solve by simplifying the query. I will post the answer.
– Daniel Elias