2

enter image description hereStrangely, it seems that the EXISTS clause is not supported by DBISAM's sql engine, as it's always resulting in an SQL error. The following is a sample where EXISTS is being used. Am i missing anything here?

update Table1 set HASXACTION = False
WHERE EXISTS (SELECT SERIALID
              From Table2  
              LEFT JOIN Table1 ON (Table2 .AUXILACT = Table1 .CODE) 
                               AND (Table2 .CHARTACT = Table1 .CHARTACT) )
Johny
  • 419
  • 4
  • 15

3 Answers3

2

I presume that you don't really want the join in the subquery. You probably intend a correlated subquery:

UPDATE Table1
    SET HASXACTION = False
    WHERE EXISTS (SELECT SERIALID
                  FROM Table2  
                  WHERE Table2.AUXILACT = Table1.CODE AND Table2.CHARTACT = Table1.CHARTACT
                 );

This should also fix the problem you are having, which is the reference to Table1 both in the update clause and the subquery. (This is a MySQL limitation.)

EDIT:

I cannot find any reference to EXISTS (or even subqueries) for dbisam. But, you can do updates with joins, so this should be equivalent:

UPDATE Table1
    SET HASXACTION = False
    FROM Table1 JOIN
         Table2
         ON Table2.AUXILACT = Table1.CODE AND Table2.CHARTACT = Table1.CHARTACT;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
2

Never mind people, i just learned that DBISAM does not support EXISTS operator for specifying sub-select predicates in WHERE clauses. It's documented within DBISAM's help file(screenshot attached).

DBISAM Help Documentation

Johny
  • 419
  • 4
  • 15
  • Well, that perfectly answers my question as well,. i was looking for a faster way to do distinct,. but seems that's not going to fly. – T.S Jul 05 '19 at 09:16
1

As you've already found, you can do it with the IN. However, there is a limitation that IN can only work with one field. So you can get around it by concatenating two fields to make expressions that fit the criteria. One for the inner, and one for the outer.

update Table1 set HASXACTION = False
WHERE Code+'.'+CHARTACT IN 
 (  
   SELECT  AUXILACT+'.'+CHARTACT From Table2
 )
Chris Thornton
  • 15,620
  • 5
  • 37
  • 62