PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

SQL · Theory

last()

← All stacks

Theory

125/439

last()

MAX(marks) highest value. Topper query: ORDER BY marks DESC LIMIT 1 or WHERE marks = (SELECT MAX(marks) FROM students). The subquery form keeps ties.

LIMIT 1 hides ties. Say that in the interview.

Trap — MAX without mentioning ties.

On the example next to this theory: last(): create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Exam tip

MAX(marks). Ties: WHERE marks = (SELECT MAX(marks) FROM students).

last() — sample query

-- last()
CREATE TABLE demo (
  id INTEGER PRIMARY KEY,
  label TEXT NOT NULL,
  qty INTEGER DEFAULT 0
);
INSERT INTO demo (id, label, qty) VALUES
  (1, 'alpha', 2),
  (2, 'beta', 5);
SELECT label, qty FROM demo WHERE qty >= 2 ORDER BY qty DESC;

last(): create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Short notes

  • DefMAX = largest non-NULL value.
  • RuleSubquery keeps ties. LIMIT 1 may hide them.
  • TrapAssuming one unique topper.

Questions

1

All toppers, not one?

125 / 439

P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.