Alternatives to IN in Oracle

Posted on 2011-10-03
Last Modified: 2013-12-19
I have a table that has 7 million unique ID's.
I'm looking for 24k that are coming off a spreadsheet.

I have read only access to the tables, so I don't think I can create
a temp table to join off of for filtering.

What would be the best way to return the ID's I want, and their
corresponding fields, given that IN only allows 1,000 arguments (I think)?
Question by:JustinW
    LVL 73

    Accepted Solution

    select * from yourtable where yourid in (1,2,3,....1000)
    or yourid in (1001,1002,...., 2000)
    or yourid in (2001, ...., 3000)


    change the inlists to be your actual values.

    LVL 1

    Author Comment

    Is this the fastest way?
    Is there not like a CTE thing you can do in oracle, like in SQLServer?
    LVL 73

    Expert Comment

    sure you could but it's unlikely to be faster
    probably not slower either  I'd expect them to be about the same

    if you like cte better, try this...

    with cte as (select 1 n from dual union all select 2 from dual union all select 3 from dual
    union all .....
    select 24000 from dual)
    select * from yourtable where yourid in (select n from cte)
    LVL 1

    Author Closing Comment

    thanks for doing both!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now