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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:07:26+00:00 2026-06-17T02:07:26+00:00

I am trying to subtract query results from two columns. Table: id | word1

  • 0

I am trying to subtract query results from two columns.

Table:

 id |   word1   | lang1 |   word2   | lang2 |
----+-----------+-------+-----------+-------+
  1 | car       |   1   | car       |  15   |
  2 | table     |   1   | table     |  15   |
  3 | Chair     |   1   | cahair    |  13   |
  4 | CDplayer  |  15   | CDplayer  |   1   |
  5 | car       |   1   | car       |  13   |

I would like to get all the words in word1 in language 1 that are not translated yet into language 12. So in this case it would be Chair

There are 3 million rows in the table and the following query takes 1 minute to run:

SELECT DISTINCT word1 
FROM `translations` 
WHERE lang1 = 1 
  AND lang2 != 15 
  AND NOT IN (SELECT word1 FROM `translations` WHERE lang2 == 15) 
LIMIT 10

Doing a select on both rows separately is very fast 0.006s and then I could use array_diff() in PHP to subtract them from one another, but there probably is a simpler way to do it directly in MySQL.

  • 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-17T02:07:27+00:00Added an answer on June 17, 2026 at 2:07 am
    SELECT 
        origin.word1
    FROM 
        ( SELECT DISTINCT word1
          FROM tableX 
          WHERE lang1 = 1
        ) AS origin
    WHERE 
        NOT EXISTS
          ( SELECT *
            FROM tableX AS trans
            WHERE trans.lang1 =  1
              AND trans.lang2 = 15
              AND trans.word1 = origin.word1
          ) ;
    

    I would add an index on (lang1, word1) and an index on (lang1, lang2, word1) before running these queries.

    You could also try this variation (and check both Explain plans):

    SELECT DISTINCT
          word1
    FROM 
          tableX AS origin
    WHERE 
          lang1 = 1
      AND 
          NOT EXISTS
          ( SELECT *
            FROM tableX AS trans
            WHERE trans.lang1 =  1
              AND trans.lang2 = 15
              AND trans.word1 = origin.word1
          ) ;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make an sql query to subtract two values from different
I have two arrayLists and I am trying to subtract one arrayList from another.
I'm trying to sum two columns, and subtract the two sums to get a
I'm trying to subtract two values from each other using twos compliment. I have
Trying to subtract a JPEG image from itself results in a non empty image,
I am trying to subtract two dates from each other in c#. My current
I am trying to subtract two values in my array the largest and the
I'm trying to subtract two unsigned ints and compare the result to a signed
Im trying to call a method that will add or subtract 1 from a
What I am trying to do is to subtract 7 hours from a date.

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.