الجمعة، 20 ديسمبر 2013

How to make this SQL query faster

I have two tables like

table1:

word ida 1a 2a 10c 20d 21e 30

table2:

id1 id21 202 21

Now if word='a' then I need to find out 'c' and 'd' using table1 and table2: I wrote a query, its working but taking too much time, because tables include huge data.

Query:

SELECT word FROM table1 WHERE id IN (SELECT id2 FROM table2 WHERE id1 IN ( SELECT id FROM table1 WHERE word = 'a'))

Another query:

SELECT DISTINCT word FROM table1 WHERE id IN (SELECT id FROM table1 WHERE word = 'a')

View the original article here

ليست هناك تعليقات:

إرسال تعليق