id title slug summary ------------------------------ 1 title1 slug1 summary1 2 title2 slug2 summary2 3 title3 slug3 summary3 4 title4 slug4 summary4
मैं सभी क्षेत्रों का चयन करने के कोशिश कर रहा हूँ, और इस बीच, चुनिंदा आईडी, शीर्षक और पिछला/अगली पंक्ति के स्लग मेंSimplifing MySQL का चयन करें
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);
क्वेरी काम करता है लेकिन जाहिरा तौर पर यह नहीं है ऐसा करने का स्मार्ट तरीका।
क्या कुछ इसे सरल बनाने में मदद कर सकते हैं? धन्यवाद
एसक्यूएल में एक बेहतर तरीका है - सीमित एसक्यूएल सुविधाओं बस के साथ नहीं MySQL है। –
हम आपसे सीखने के लिए उत्सुक हैं। – 0xC0DEGURU