Sibir
Sibir

Reputation: 313

Two SQLite queries at one go

I have two queries:

SELECT word FROM dictionary WHERE lang = 'english' AND word LIKE 'k%' LIMIT 10;
SELECT word FROM dictionary WHERE lang = 'english' AND word LIKE 's%' LIMIT 10;

Because the database is huge, each query takes time. So, my question is that can I merge the above queries into one with a LIMIT of 5 each? If yes, then how to do it?

Any help is appreciated. Thanks.

Upvotes: 0

Views: 33

Answers (1)

Rahul Tripathi
Rahul Tripathi

Reputation: 172448

Try like this:

SELECT * from (select word FROM dictionary WHERE lang = 'english' AND word LIKE 'k%' LIMIT 5)
UNION ALL
SELECT * from (select word FROM dictionary WHERE lang = 'english' AND word LIKE 's%' LIMIT 5);

Also to retrieve the data in a faster way you can create index on your column.

Upvotes: 1

Related Questions