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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:57:23+00:00 2026-05-22T16:57:23+00:00

I’ve been looking for ages about how to do a query like this but

  • 0

I’ve been looking for ages about how to do a query like this but use an index.

SELECT * FROM aliens_tmp 
WHERE creator !=  'a'
AND COUNTRY = 'UK' 
ORDER BY id DESC LIMIT 0, 10

Whatever index I create will not get a hit because of the != clashing with the inclusive nature of indexes.

So I thought about doing a minus where I do something like

SELECT * FROM aliens_tmp 
WHERE COUNTRY = 'UK 
MINUS
SELECT * FROM aliens_tmp 
WHERE CREATOR = 'a' 
ORDER BY id DESC LIMIT 0, 10

…but MINUS doesn’t exist. So I looked and figured I could use the old trick mentioned on http://www.bitbybit.dk/carsten/blog/?p=71 which briefly is

SELECT DISTINCT a.member_id, a.name
FROM a LEFT JOIN b USING (member_id, name)
WHERE b.member_id IS NULL

but that doesn’t help me with the original goal of doing a MINUS whilst maintaining the use of an index as any join to my own table still has to exclude my creator which causes the miss because of the exclude Any ideas?

  • 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-22T16:57:23+00:00Added an answer on May 22, 2026 at 4:57 pm

    If most of your table consists of rows with creator != 'a' then using index will not give you any advantage. However if you have mostly rows with creator='a' then you can consider assigning such values to creator (or using enum) that if you order by creator ‘a’ would go first. Instead of checking for creator != 'a' you could then use creator > 'a' condition, which is perfectly fine for using btree indexes.

    UPDATE after more info about creator:

    So your creator != 'a' condition has extremely low selectivity and trying to use index on creator is pointless. You are limiting your results and ordering by id desc, so the key on country should be used to return as few rows as possible by simply checking every single row starting from highest id whether it satisfies where conditions until there are enough for your limit. If you see key: country and number of rows close to 10 in your explain select ... it won’t get any faster.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is

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.