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

  • Home
  • SEARCH
  • 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 3276672
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:17:03+00:00 2026-05-17T19:17:03+00:00

I have a query that looks something like SELECT to_number FROM sent_texts WHERE to_number

  • 0

I have a query that looks something like

SELECT to_number FROM sent_texts 
WHERE to_number NOT IN(SELECT mobile FROM action_6_members);

A WHERE is applied to the result set after the query is complete.
What would the effect be (improve/degrade) if the sub query contained

WHERE mobile = to_number

A HAVING is applied to the result set during the query.
What would the effect be (improve/degrade) if the sub query contained

HAVING mobile = to_number

What are the pros/cons of just using the original query?


Update
It seems my initial thoughts were wrong, thanks to Bill Karwin’s answer.

So Im going to update this with the explain of the original query.

This query is causing me my server to use 100% of the cpu.

Maybe someone can say why, and how to fix it?

id  select_type         table             type   possible_keys  key        key_len  ref  rows    Extra                     
2   DEPENDENT SUBQUERY  action_6_members  index                 mobile     42            179218  Using where; Using index  
1   PRIMARY             sent_txts         index                 to_number  123           256066  Using where; Using index   

This is the explain based off the join(after some more optimization)

id  select_type  table             type   possible_keys  key        key_len  ref  rows    Extra                                 
1   SIMPLE       sent_txts         index                 to_number  78            256066  Using index                           
1   SIMPLE       action_6_members  index                 mobile     27            179218  Using where; Using index; Not exists  
  • 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-17T19:17:04+00:00Added an answer on May 17, 2026 at 7:17 pm

    Just use the original query. MySQL optimizes this case all right, especially if mobile is an indexed column. It runs the non-correlated subquery once, and compares to_number to the set of mobile numbers reasonably efficiently.

    I don’t know where you got the ideas about WHERE conditions being applied after the query and HAVING conditions being applied during the query. This is not accurate.

    Think of it this way:

    • WHERE conditions eliminate rows from the result set. This is done during the query.

    • HAVING conditions eliminate groups from the result set. This is also done during the query, but after GROUP BY has collected rows into groups.

      You should not use HAVING if you aren’t using GROUP BY.

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

Sidebar

Related Questions

I have a Linq query that looks something like this: var myPosse = from
I have a Linq query that looks something like this: var query = from
I have a query that looks like this SELECT * from myTable WHERE Date
I have a query that looks a bit like this: SELECT weekEnd, MAX(timeMonday) FROM
I have a query that looks like this: var ChangesOthersResult = surveyResponseRepository.Query.Select(r => r.ChangesOthers);
I have a query that looks like SELECT P.Column1, P.Column2, P.Column3, ... ( SELECT
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
I have an NHibernate query that looks like this: var query = Session.CreateQuery(@ select
I've got a sub-select in a query that looks something like this: left outer
I have a fairly complex query that looks something like this: create table Items(SomeOtherTableID

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.