sql >> Database >  >> RDS >> Mysql

Hoe afhankelijke subquery om te zetten om deel te nemen voor betere prestaties?

Probeer eerst deze zoekopdracht -

SELECT
  t.*, ti1.*
FROM
  themes t
JOIN theme_images ti1
  ON ti1.theme_id = t.theme_id
JOIN (SELECT theme_id, MIN(image_id) image_id FROM theme_images GROUP BY theme_id) ti2
  ON ti1.theme_id = ti2.theme_id AND ti1.image_id = ti2.image_id
ORDER BY 
  t.theme_date_last_modification DESC
LIMIT 10

Nog een oplossing -

SELECT
  t.*, ti.*
FROM
  themes t
JOIN (SELECT * FROM theme_images ORDER BY image_id) ti
  ON ti.theme_id = t.theme_id
GROUP BY
  theme_id 
ORDER BY 
  t.theme_date_last_modification DESC
LIMIT
  10

Voeg vervolgens uw WHERE-filter toe.



  1. Entity Framework's Entity Data Wizard crasht bij verbinding met MySQL-database

  2. MySQL:WIJZIG TABEL als kolom niet bestaat

  3. Php/MySql-array zoeken met ã, š, é, ë, ú, ü, í, ž

  4. Oracle SQL - max() met NULL-waarden