Question: I've downloaded the [Tatoeba project databases](http://tatoeba.org/eng/download_tatoeba_example_sentences) and I'm trying to query them but queries with a subquery are taking way too long.

```
-- 800.000 rows approx.
CREATE TABLE `sentences` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `language` char(3) DEFAULT NULL,
  `text` mediumtext,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=912551 DEFAULT CHARSET=utf8

-- 1.5 million rows approx.
CREATE TABLE `links` (
  `sentenceId` int(10) unsigned NOT NULL,
  `translatedId` int(10) unsigned NOT NULL,
  PRIMARY KEY (`sentenceId`,`translatedId`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

```

Basically the links table joins two sentences in the `sentences` table together (the original sentence and one translation). A sentence can have zero or more translations. So I have an id of a sentence I want to work with and want to grab ALL the translations available.

**This query gets me what I want but takes almost 18 seconds to complete.**

```
SELECT * FROM `sentences` WHERE `id` IN (SELECT `translatedId` FROM `links` WHERE `sentenceId` = 157967);

```

Running both queries by themselves just takes an instant. 

What am I doing wrong?

Answer: 
```
SELECT `sentences`.* FROM 
  `sentences` JOIN 
  `links` ON `id` = `translatedId` 
WHERE `sentenceId` = 157967;

```

Some versions of MySQL are known not to use indexes in sub-queries.
Try this(using an EXISTS clause):

```
SELECT * 
    FROM `sentences` a
 WHERE EXISTS (SELECT 1 FROM `links` b WHERE `sentenceId` = 157967 AND b.`translatedId`=a.`id`); 

```

If the translatedId is unique in the `links` you can go for a inner join as given below

```
SELECT a.* 
    FROM `sentences` a INNER JOIN `links` b
      ON b.`translatedId`=a.`id`

```