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 8343895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:12:20+00:00 2026-06-09T06:12:20+00:00

I have a query that seems to take far too long to execute. It’s

  • 0

I have a query that seems to take far too long to execute. It’s been a while (years) since I’ve done anything much beyond very simple select/update and v.simple joins so I’m more than a little rusty here!

SELECT count(distinct r.TAGCODE)
FROM RAWREADS r
where r.TAGCODE NOT IN (
    select distinct r.TAGCODE 
    from RAWREADS r, checkpoints c, guards g, INCIDENTITEMS i
        where r.TAGCODE = c.TAGNO
        or    r.TAGCODE = g.IDTAG
        or    r.TAGCODE = i.IDTAG
    );

The inner select seems to work correctly, if slowly (several seconds) but as soon as I add the outer ‘count where not in’ I end up having to kill my DB connection – so no good for working into an application! 😉

I hope the query above is clear what I’m trying to achieve… fetch all rawread tags where that tag does not match the respective columns in checkpoints/guards/incidentitems.

I’m using the Flamebird database server (no choice on that) and FlameRobin to run the query if that matters.

At some point I also need to add a query to the outer select to ensure I don’t select any rawreads where the tagcode is null or “”.

I have removed a “char_length(tagcode) > 0” criteria from the out select in the hope of speeding things along but I think my problem is more fundamental than that.

  • 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-06-09T06:12:21+00:00Added an answer on June 9, 2026 at 6:12 am

    Many databases (and maybe Firebird as well) cannot easily optimize NOT IN conditions. So you might try to rerwrite this as a NOT EXTISTS.

    Additionally looking at the inner select, I think the way you are joining there is producing too many rows. It’s not a real join but not a cartesian product either. Anyway I could imagine that doing a UNION in there is also more efficient.

    So try this:

    SELECT count(distinct r.TAGCODE)
    FROM RAWREADS r
    where NOT EXISTS (
        select 1
        from checkpoints c
        where c.tagno = r.tagcode
        union all
        select 1 
        from guards g
        where g.idtag = r.tagcode
        union all 
        select 1 
        from INCIDENTITEMS i
        where i.idtag = r.tagcode);
    

    If you have indexes on checkpoints(tagno), guards(idtag) and incidentitems(idtag) that should run fairly quick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySql query that take a very long time to run (about
It seems that every time I want to perform a db query, I have
I have have this query that i want to execute. SELECT warehouse.expiry_date, pharmacy.expiry_date, drugs.active_substance,
In one of my process I have this SQL query that take 10-20% of
I have a couple of queries for a web site that take a long
I have a long running query that returns a large data set. This query
I have a linq to sql query that produces duplicates. i can seem to
i have some problems with a Query seem IN dosen't work with Group_concat, that
I am using in C# MYsql .I have query that works if I run
I have a query that successfully grabs the unique products from my products table

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.