Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6181303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:59:45+00:00 2026-05-24T00:59:45+00:00

I am attempting to refactor several old pieces of code… I have refactored the

  • 0

I am attempting to refactor several old pieces of code… I have refactored the current piece below and have highlighted the NOT IN statement causing performance issues. I am attempting to rewrite the NOT IN section with a left outer join.

Can anyone help, or suggest a better way if possible?

SELECT 
    left(unique_id,16) AS casino_id , 
    right(unique_id,24) AS game_id   
FROM (  
        SELECT 
            distinct o.casino_id + g.game_id AS unique_id      
        FROM 
            game g INNER JOIN Bet b
            ON g.game_id = b.game_id
            INNER JOIN CasinoUser u 
            ON b.user_id = u.user_id
            INNER JOIN onewalletcasino o  
            ON u.casino_id = o.casino_id
        WHERE 
            game_start between dateadd(mi, -180, getdate()) 
            and dateadd(mi, -5, getdate())  
            and b.[status] <> 'P'
     ) t 
WHERE  
   unique_id NOT in  
    ( SELECT casino_id + game_id  AS casino_id 
      FROM 
        thirdpartysettlecalled  
      WHERE 
        [status] = 'Y')
ORDER BY casino_id 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:59:45+00:00Added an answer on May 24, 2026 at 12:59 am

    You have a column concatenation which prevents any use of indexes

    Try NOT EXISTS which will support the 2 columns separately

    SELECT distinct
         o.casino_id, g.game_id
    FROM 
        game g 
        INNER JOIN 
        Bet b ON g.game_id = b.game_id
        INNER JOIN
        CasinoUser u ON b.user_id = u.user_id
        INNER JOIN
        onewalletcasino o  ON u.casino_id = o.casino_id
    WHERE 
        game_start between dateadd(mi, -180, getdate()) 
                           and dateadd(mi, -5, getdate())  
        and
        b.[status] <> 'P'
        AND
        NOT EXISTS (SELECT *
               FROM 
                  thirdpartysettlecalled   tp
               WHERE 
                  tp.[status] = 'Y'
                  AND
                  tp.casino_id = o.casino_id AND tp.game_id = g.game_id)
    ORDER BY
        casino_id 
    

    After that, check your indexes or course…

    This is a good use of EXCEPT too (ORDER BY goes at end like UNION: thanks to @Damien_The_Unbeliever)

    SELECT distinct
         o.casino_id, g.game_id
    FROM 
        game g 
        INNER JOIN 
        Bet b ON g.game_id = b.game_id
        INNER JOIN
        CasinoUser u ON b.user_id = u.user_id
        INNER JOIN
        onewalletcasino o  ON u.casino_id = o.casino_id
    WHERE 
        game_start between dateadd(mi, -180, getdate()) 
                           and dateadd(mi, -5, getdate())  
        and
        b.[status] <> 'P'
    
    EXCEPT
    SELECT tp.casino_id, tp.game_id
    FROM thirdpartysettlecalled   tp
    WHERE tp.[status] = 'Y'
    
    ORDER BY
        casino_id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Attempting to generics-ify some legacy code, I'm stuck. I have a ParentObject which wraps
I am trying attempting to refactor the following code: public static void SaveSplitbar(RadSplitBar splitBar)
Attempting/struggling to get registration and sign-up working within an active admin project. I have
Attempting a beginner's tutorial. I have the following in my head: <script type=text/javascript charset=utf-8
Attempting to compile the following code under Qt SDK 4.7.4 for Desktop - MinGW
Attempting to follow the directions as specified on http://code.google.com/p/gears/wiki/BuildingGearsForWindows my attempts are failing at
I'm attempting to refactor a cumbersome LINQ-to-SQL data layer with an entity framework one.
I have a pixel/location, we'll call it 4,4 on a graph. I'm attempting to
I'm attempting to compile Java 1.4 code that was created by IBM's WSDL2Java on
I've been attempting to refactor a fairly simple three or four page site to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.