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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:37:07+00:00 2026-05-28T13:37:07+00:00

This is the query I’m talking about: SELECT COUNT FROM Note N, DatePCC D

  • 0

This is the query I’m talking about:

SELECT COUNT
FROM Note N, DatePCC D
WHERE D.codClient = '2' AND 

((D.CodPCC = N.CodPCC AND D.TipPCC = N.TipPCC) OR (D.CodPCC = N.CodPCCOA AND D.TipPCC = N.Relatie)) 

AND (N.user = 'Server' OR N.user = 'ADMIN' OR N.user = 'Simona' OR N.user = 
'Viorel' OR N.user = 'Dan' OR N.user = 'Razvan') AND (N.TipNota = 'Telefon' OR N.TipNota = 
'Messenger' OR N.TipNota = 'Telefon esuat' OR N.TipNota = 'Email' OR N.TipNota = 'Evaluare 
curs' OR N.TipNota = 'Corespondenta' OR N.TipNota = 'Vizita') AND 
(DATE(N.DataInregistrarii) >= '2000-01-01' AND DATE(N.DataInregistrarii) <= '2012-01-25') 
AND 1

The problem come from the line i’ve singled out. When I use it as simply

(D.CodPCC = N.CodPCC AND D.TipPCC = N.TipPCC) 

the query runs almost instantly but after I add the second part it locks up our database. I can’t, for the life of me, figure out why it impacts the duration so much since it’s simply another two comparisons among many other.

What the query does is select stuff from N X D Where either these two (CodPCC, TipPCC) from N coincide with CodPCC and TipPCC from D or (CodPCCOA, Relatie) from N coincide with the same two rows from D.

Any idea how those two simple comparisons are changing the query in such a huge way? or how I could change it to work properly?

  • 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-28T13:37:08+00:00Added an answer on May 28, 2026 at 1:37 pm

    The big difference is because you are changing a simple inner join into an expression that has to be evaluated on a cross join between the tables.

    You shouldn’t write your join that way in the first place, but use the join keyword:

    select COUNT
    from Note N
    inner join DatePCC D on D.codClient = '2' and D.CodPCC = N.CodPCC and D.TipPCC = N.TipPC
    where ...
    

    To make the new query efficient, you should make two left joins against the same table. That way the database can use index for each join instead of making a cross join.

    select COUNT
    from Note N
    left join DatePCC D on D.codClient = '2' and D.CodPCC = N.CodPCC and D.TipPCC = N.TipPC
    left join DatePCC D2 on D2.codClinent = '2' and D.CodPCC = N.CodPCCOA AND D.TipPCC = N.Relatie
    where ...
    

    You can also try if an inner join is efficient with the two sets of conditions, but it’s possible that the database can’t optimise that into a good query.

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

Sidebar

Related Questions

In this query: SELECT COUNT(*) AS UserCount, Company.* FROM Company LEFT JOIN User ON
This query SELECT FirstName, LastName, NCAAStats.AccountId, College_Translator.school_name, StatTypeId, COUNT(*) AS 'Count' FROM NCAAstats INNER
This query works: item = db.GqlQuery(SELECT * FROM Item WHERE CSIN = 13)[0] although
Take this query: SELECT * FROM MyTable WHERE MyColumn = 'SomeValue' ORDER BY SomeFakeQualifier.MyColumn
Why this query doesn’t working: SELECT name FROM ( SELECT name FROM table1 UNION
This query fails when I add the line shown... Select Companyid, count(*) as cnt
This query is working fine: SELECT * FROM tablename where Date >'20091109' and id='11';
This query pops up in my slow query logs: SELECT COUNT(*) AS ordersCount, SUM(ItemsPrice
This query SELECT PA.refPatient_id ,MAX(PA.datee) AS datee ,PR.temporary,PA.statue FROM PatientClinicActs AS PA ,PatientStatueReasons AS
This query: SELECT refPatient_id,actDate,refReason_id,refClinic_id,active FROM PatientClinicHistory WHERE refClinic_id = 24 GROUP BY refPatient_id,actDate,refReason_id,refClinic_id,active ORDER

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.