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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:53:37+00:00 2026-06-18T08:53:37+00:00

I got a table with over 12 columns. This is the mysql query used

  • 0

I got a table with over 12 columns. This is the mysql query used to retrive the latest 7 records

SELECT * FROM data WHERE user_id IN(12,10,7,1) HAVING continent IN('Europe','America','Australia') AND NOT MATCH(weather) AGAINST('+"[blues]"' IN BOOLEAN MODE) || continent = 'Asia' AND MATCH(weather) AGAINST('+"[purples]"' IN BOOLEAN MODE) ORDER BY tb_id DESC LIMIT 7

Total rows are more than 5 million and user_id is an indexed column with tb_id being the PRIMARY KEY. When i use the EXPLAIN in front of SELECT. MySQL tells that it will read over 400 thousand records from a total of 5 million.

So should I index continent column or it won’t help in this case?

Here is the EXPLAIN result

id = 1; select_type = SIMPLE; table = data; possible_keys = user_id; key = user_id; ref = NULL; rows = 582; Extra = Using where, Using filesort

  • 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-18T08:53:38+00:00Added an answer on June 18, 2026 at 8:53 am

    First of all, your query is probably wrong. When you use OR mixed with AND in where or having clause or anywhere, you should use parantheses.

    Second, using HAVING in your case doesn’t make sense and the optimizer will most likely convert it to a WHERE clause.

    The difference between the two is, that WHERE is applied when determining which rows to select. HAVING is applied on the result set. So, if the optimizer wouldn’t do a good job, you would first get (almost) all rows, then filter those. When you put it all in the WHERE clause, you get only the relevant rows. HAVING (almost) only makes sense when you are using GROUP BY.

    So, you better write your query this way:

    SELECT * FROM data 
    WHERE user_id IN(12,10,7,1) AND
    (
    (
    continent IN('Europe','America','Australia') 
    AND NOT MATCH(weather) AGAINST('+"[blues]"' IN BOOLEAN MODE) 
    )
    OR 
    (
    continent = 'Asia' 
    AND MATCH(weather) AGAINST('+"[purples]"' IN BOOLEAN MODE) 
    )
    )
    ORDER BY tb_id DESC LIMIT 7
    

    To answer your question about the index, post the result of the explain and the create statements of your table data.

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

Sidebar

Related Questions

I've got table with two columns: name and grade. It looks sth like this:
I got a table like this, and use MYSQL 5.5 id --- 2 3
I've been trying to get this complex MYSQL query to work exactly right over
Say I've got a table with two columns (date and price). If I select
I got a table which tracks positions over time. This table contains a lot
I got a table with over 6.6 millions rows. I got a field, named
I've got a very large SQLite table with over 500,000 rows with about 15
Got this: Table a ID RelatedBs 1 NULL 2 NULL Table b AID ID
I've got a TABLE that's actually being used for its intended purpose, to display
I have table one which looks like this. And I want to get data

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.