Subject | RE: [firebird-support] Doubts about exists predicate |
---|---|
Author | Svein Erling Tysvær |
Post date | 2010-11-16T09:33:35Z |
IN is good when using constants, EXISTS when involving a subselect. I.e. I would use
Select Field1, Field2 from Table1 where Field3 IN ('Value1', 'Value2', 'Value3');
whereas I would replace
Select t1.Field1, t1.Field2 from Table1 t1 where t1.Field3 IN (select t2.Field3 from Table2 T2);
with
Select t1.Field1, t1.Field2 from Table1 t1 where exists(select * from Table2 T2 where t1.Field3 = t2.Field3);
To be precise (normally it is not a practical issue, it is only relevant when dealing with NULL), IN (<subselect>) can always be replaced by EXISTS, whereas NOT IN (<subselect>) isn't always identical to NOT EXISTS.
HTH,
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Tanmoy Ghoshal
Sent: 16. november 2010 09:58
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Doubts about exists predicate
Hi All,
I am using Firebird 2.1.3. I have some doubt about
exists predicate, can we directly use (if yes, then how, pl need an
example) as follows:
Select Field1, Field2 from Table1 where Field3 IN ('Value1', 'Value2', 'Value3');
same
can we use Exists predicate in above sql instead of IN, provided values
will be given same, as it is given in above sql like 'Value1',
'Value2'.....
Second doubt there value limitation for IN predicate as 1500, is there any limitation for Exists predicate?
I am beginner to sql, pl let me know.
Thanks In Advance.
Tanmoy
Select Field1, Field2 from Table1 where Field3 IN ('Value1', 'Value2', 'Value3');
whereas I would replace
Select t1.Field1, t1.Field2 from Table1 t1 where t1.Field3 IN (select t2.Field3 from Table2 T2);
with
Select t1.Field1, t1.Field2 from Table1 t1 where exists(select * from Table2 T2 where t1.Field3 = t2.Field3);
To be precise (normally it is not a practical issue, it is only relevant when dealing with NULL), IN (<subselect>) can always be replaced by EXISTS, whereas NOT IN (<subselect>) isn't always identical to NOT EXISTS.
HTH,
Set
-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Tanmoy Ghoshal
Sent: 16. november 2010 09:58
To: firebird-support@yahoogroups.com
Subject: [firebird-support] Doubts about exists predicate
Hi All,
I am using Firebird 2.1.3. I have some doubt about
exists predicate, can we directly use (if yes, then how, pl need an
example) as follows:
Select Field1, Field2 from Table1 where Field3 IN ('Value1', 'Value2', 'Value3');
same
can we use Exists predicate in above sql instead of IN, provided values
will be given same, as it is given in above sql like 'Value1',
'Value2'.....
Second doubt there value limitation for IN predicate as 1500, is there any limitation for Exists predicate?
I am beginner to sql, pl let me know.
Thanks In Advance.
Tanmoy