Ravindra Bagale · Cyber Securityसर्व coursesया course चे lessonsशोधाEnglish

Cyber Security · मराठी आवृत्ती

ORDER BY, LIMIT, DISTINCT आणि aliases

रवींद्र बागले यांच्या course वर आधारित · सहज मराठीत explanation

या page मध्ये

आता results sort करू, मोजके rows घेऊ आणि output names बदलू.

SELECT name, fees_paid FROM students ORDER BY fees_paid DESC;       -- highest first
SELECT name, city, age FROM students ORDER BY city ASC, age DESC;   -- two-level sort
SELECT name, fees_paid FROM students ORDER BY fees_paid DESC LIMIT 3;   -- top 3
SELECT name FROM students ORDER BY student_id LIMIT 3 OFFSET 3;     -- rows 4-6 (pagination)
SELECT DISTINCT city FROM students;                                 -- unique values
SELECT name AS student_name, fees_paid * 1.18 AS fees_with_tax FROM students;
SELECT s.name, s.city FROM students AS s WHERE s.age < 23;          -- table alias

DESC मोठ्यापासून लहान, ASC लहानापासून मोठा. दोन columns दिल्यास आधी पहिला, ties साठी दुसरा sort. LIMIT 3 तीन rows; OFFSET 3 आधीचे तीन skip. Deterministic pagination साठी unique tie-breaker, जसं student_id, वापरा.

DISTINCT city unique cities देतो. AS column/table alias देतो. Fees ×1.18 हा गणित शिकवण्याचा example आहे; तो actual tax advice/rate नाही.

Security मध्ये उपयोग

Vulnerable query वर ORDER BY column positions च्या errors मधून result-column count बाबत clue मिळू शकतो. Source यातून UNION-based SQL injection च्या पुढच्या authorized lab कडे संदर्भ देतो. Errors visitors ना उघड न करणे आणि query structure सुरक्षित ठेवणे महत्त्वाचं.

Practice

तीन youngest students, alphabetic unique cities आणि प्रत्येक page चार rows असताना दुसरं page दाखवा. NULL age असल्यास youngest मध्ये कसं हाताळायचं ते ठरवा; missing age ला प्रत्यक्ष सर्वांत कमी age समजू नका.