id title slug summary ------------------------------ 1 title1 slug1 summary1 2 title2 slug2 summary2 3 title3 slug3 summary3 4 title4 slug4 summary4
che sto cercando di selezionare tutti i campi, e nel frattempo, selezionare ID, titolo e sorso di prev/riga successivasemplificando MySQL SELECT nidificato
SELECT
title, slug, summary, id as current_id,
(SELECT id FROM table WHERE id < current_id ORDER BY id DESC LIMIT 1) AS prev_id,
(SELECT title FROM table WHERE id < current_id ORDER BY id DESC LIMIT 1) AS prev_title,
(SELECT slug FROM table WHERE id < current_id ORDER BY id DESC LIMIT 1) AS prev_slug,
/*
(SELECT id ... ) AS next_id
(SELECT title...) AS next_title
...
and if there are more fields to select, I have to repeat this (SELECT...)
*/
FROM
table
WHERE
id IN (2,3,4);
Le opere di query, ma a quanto pare non è il modo intelligente per farlo.
Alcuni possono aiutare a semplificare questo? Grazie
C'è un modo migliore in SQL, non solo con le funzionalità SQL limitate di MySQL. –
siamo desiderosi di imparare da voi. – 0xC0DEGURU