Mihai Stancioiu
Mihai Stancioiu

Reputation: 794

a query improvement

Can somebody suggest me an improvement for the following query.

$q = "
    SELECT q. *
      FROM questions q, answers a
     WHERE q.questions LIKE '%".$str."%'
        OR a.answers   LIKE '%".$str."%'
       AND q.id = a.id_questions
  GROUP BY q.id
     LIMIT 10"

It is used in a search on a database with >100.000 questions and answers.

With less records works ok, but now...

Even with limit 10 the server gone away

Upvotes: 1

Views: 58

Answers (1)

jexact
jexact

Reputation: 541

try this:

SELECT     q.*
FROM       questions q
INNER JOIN answers a
ON         q.id = a.id_questions
WHERE      q.questions LIKE '%yourstring%'
OR         a.answers LIKE '%yourstring%'
GROUP BY   q.id

Upvotes: 2

Related Questions