View Single Post

   
  #3 (permalink)  
Old 02-28-2008, 09:48 AM
Michael Austin
 
Posts: n/a
Default Re: select .. where ..in TOO LONG

Josselin wrote:
> I need to perform a select based on a list of id's , it's fine when the
> number of id's is not too big, but when It can be very large..
>
> what options could I have ?
>
> create a temporary table and match with this table ... each time I need
> to perform the select... ?
> no better option in term of performances ?
>
> thanks for yoru lights
>
> joss
>


The method used depends on how you choose which ID's to look for. If the data is
derived from the database and not user input, then you can use a derived table -
basically a view on-the-fly:

select field1,field2 from tablea where id in (select id from table2 where
somevalue=somecriteria);

or

select temptab.field1, temptab.field2 from (select id, field1,field2 where
somevalue=someothervalue) temptab ;

or use a join

select a.field1, b.field2 from table1 a join table2 b on a.id=b.id
where b.status = 1;

You have a database engine and these are just starting points...

--
Michael Austin.
Database Consultant
Reply With Quote