Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is pretty huge, and would probably perform better if you did some of it in the application layer, but something like this should do it:</p> <pre><code>select * from ( SELECT * FROM movies WHERE mov_type=1 and mov_title LIKE '%" . $queryString . "%' AND mov_status = 1 AND mov_incomplete = 0 LIMIT 5 UNION ALL SELECT * FROM movies WHERE mov_type=2 and mov_title LIKE '%" . $queryString . "%' AND mov_status = 1 AND mov_incomplete = 0 LIMIT 5 UNION ALL SELECT * FROM movies WHERE mov_type=1 and mov_title LIKE '%" . $queryString . "%' AND mov_status = 1 AND mov_incomplete = 0 AND id not in ( SELECT id FROM movies WHERE mov_type=1 and mov_title LIKE '%" . $queryString . "%' AND mov_status = 1 AND mov_incomplete = 0 LIMIT 5 ) LIMIT 5 UNION ALL SELECT * FROM movies WHERE mov_type=2 and mov_title LIKE '%" . $queryString . "%' AND mov_status = 1 AND mov_incomplete = 0 AND id not in ( SELECT id FROM movies WHERE mov_type=2 and mov_title LIKE '%" . $queryString . "%' AND mov_status = 1 AND mov_incomplete = 0 LIMIT 5 ) LIMIT 5 ) a LIMIT 10 </code></pre> <p>It would be a good idea to move some of this business logic into a view to avoid so much repetition, e.g.:</p> <pre><code>create view ActiveMovies as SELECT * FROM movies WHERE mov_status = 1 AND mov_incomplete = 0 </code></pre> <p>Then it would look more like:</p> <pre><code>select * from ( SELECT * FROM ActiveMovies WHERE mov_type=1 and mov_title LIKE '%" . $queryString . "%' LIMIT 5 UNION ALL SELECT * FROM ActiveMovies WHERE mov_type=2 and mov_title LIKE '%" . $queryString . "%' LIMIT 5 UNION ALL SELECT * FROM ActiveMovies WHERE mov_type=1 and mov_title LIKE '%" . $queryString . "%' AND id not in ( SELECT id FROM ActiveMovies WHERE mov_type=1 and mov_title LIKE '%" . $queryString . "%' LIMIT 5 ) LIMIT 5 UNION ALL SELECT * FROM ActiveMovies WHERE mov_type=2 and mov_title LIKE '%" . $queryString . "%' AND id not in ( SELECT id FROM ActiveMovies WHERE mov_type=2 and mov_title LIKE '%" . $queryString . "%' LIMIT 5 ) LIMIT 5 ) a LIMIT 10 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload