Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make this query run faster?
    primarykey
    data
    text
    <p>I have query like this:</p> <pre><code> SELECT `om_chapter`.`manganame` as `link`, (SELECT `manganame` FROM `om_manga` WHERE `Active` = '1' AND `om_manga`.`link` = `om_chapter`.`manganame` LIMIT 0,1) AS `manganame`, (SELECT `cover` FROM `om_manga` WHERE `Active` = '1' AND `om_manga`.`link` = `om_chapter`.`manganame` LIMIT 0,1) AS `cover`, (SELECT `othername` FROM `om_manga` WHERE `Active` = '1' AND `om_manga`.`link` = `om_chapter`.`manganame` LIMIT 0,1) AS `othername` FROM `om_chapter` WHERE `Active` = '1' AND (SELECT `Active` From `om_manga` WHERE `om_manga`.`link` = `om_chapter`.`manganame` LIMIT 0,1) AND `id` IN ( SELECT MAX(`id`) FROM `om_chapter` WHERE `Active` = '1' GROUP BY `manganame` ) ORDER BY `id` DESC LIMIT 10 </code></pre> <p>So how can I make this query faster?</p> <p>Here are my tables:</p> <p>om_chapter:</p> <pre><code>id | manganame | chapter | Active ----------------------------------------- 1 | naruto | 1 | 1 2 | naruto | 12 | 1 3 | naruto | 22 | 1 4 | bleach | 10 | 1 5 | bleach | 15 | 1 6 | gents | 1 | 1 7 | naruto | 21 | 1 </code></pre> <p>om_manga:</p> <pre><code>id | othername | manganame | cover | Active ----------------------------------------------------- 1 | naruto | naruto | n.jpg | 1 2 | bleach | bleach | b.jpg | 1 4 | gents | gents | g.jpg | 1 </code></pre> <p>First thing i want form this query is to give me 10 last rows form om_chapter by grouping manganame and ordering by id.. i try to use a simple query by using group or even distinct but none of them give me the right result... </p> <p>In a simple query with group or distinct, the result is like this:</p> <pre><code>id | manganame | chapter | Active ----------------------------------------- 7 | prince | 21 | 1 5 | gent | 15 | 1 2 | naruto | 12 | 1 1 | bleach | 1 | 1 </code></pre> <p>But i want this result: </p> <pre><code>id | manganame | chapter | Active ----------------------------------------- 9 | gents | 21 | 1 8 | bleach | 21 | 1 7 | prince | 21 | 1 6 | naruto | 1 | 1 </code></pre> <p>So i use this:</p> <pre><code>WHERE `Active` = '1' AND (SELECT `Active` From `om_manga` WHERE `om_manga`.`link` = `om_chapter`.`manganame` LIMIT 0,1) AND `id` IN ( SELECT MAX(`id`) FROM `om_chapter` WHERE `Active` = '1' GROUP BY `manganame` ) </code></pre> <p>And i use sub select in where because i want Active's field in om_manga's table be 1..</p> <p>For the reset of sub select, i actually didn`t try join, but i will..!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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