Subject Re: Facing Problem with limitations of IN CLAUSE
Author Ali Gökçen
Hi Kapil,
I dislike such type kamikaze queries but anyway,
sometimes we need it..
(for example, fetch some rows from large tables on day and month
values using index. bithday list etc..)

Try this:

create view wt1 (id)
as
select id from t1 where id in(1,...,1499)
union all
select id from t1 where id in(1500,...,2998)
union all
select id from t1 where id in(3000,...,4997);


select x.grpfield,max(x.valuefield) from t1 x
join t1 y on y.id=x.id
group by 1


Regards.
Ali

--- In firebird-support@yahoogroups.com, "Kapil Patil"
<kapilpatil84firebird@...> wrote:
>
>
> As per my knowledge I know that IN CLAUSE have limitations of only
1499
> elements. (firebird v2.0)
>
> I have one query where IN CLAUSE elements exceeds above 4000
therefore
> firebird gives error...
>
> I tried entering the elements in temp. table and then using the
>
> SELECT ........ from TABLENAME where ...... in (Select .. from
> TEMPTABLE)
>
> It works, but quiet slow because I have to first insert the
elements in
> TEMP TABLE and
> then fire the main query as shown above.
>
> I Also tried using combination of IN and OR Operator as
>
> select ... from tablename where .. in (1,2,3,4,5,6....,1499)
or ... in
> (1500.......) or ... in(.......)
>
> But this works very very slow taking around 8 to 10 minutes and
> sometimes even more, so not very effective query
>
> Some one suggested me to break the query in two or more
> like first 1499 elements in one query and then fire and get the
records
> and then
> next 1499 elements and get the records and so .. on
>
> but the problem is that I want to order by clause and with this
approach
> it is not possible to sort the data....
> and secondly If query contains aggregate functions like SUM, MAX,
MIN
> ..... in that case
> firing query with first 1499 elements and so..on will give me
wrong
> results
>
> SO, Is there any way to overcome this limitations with out
creating any
> TEMP TABLE
>
> Thanks In advance,
>
> Kapil Patil
>
>
>
>
>
>
> [Non-text portions of this message have been removed]
>