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

SQL · Theory

RAND()()

← All stacks

Theory

211/439

RAND()()

RAND() is a MySQL math function: random 0–1. ORDER BY RAND() LIMIT 1 picks a random row (slow on huge tables). Use it in SELECT, e.g. SELECT RAND(marks) FROM students;

These functions do not change stored marks unless you UPDATE. NULL in, NULL out for most of them.

ORDER BY RAND() LIMIT 1 is the interview random-row trick. On a large table it is expensive — say that.

In a viva, one numeric example beats listing twenty functions.

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

Exam tip

Explain RAND with one number. random 0–1. ORDER BY RAND() LIMIT 1 picks a random row (slow on huge tables).

RAND()() — sample query

-- RAND()()
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;

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

Short notes

  • DefRAND() — random 0–1. ORDER BY RAND() LIMIT 1 picks a random row (slow on huge tables).
  • RuleSELECT the function; UPDATE only if you mean to store it.
  • TrapNULL in → NULL out. Don’t confuse with table TRUNCATE.

Questions

1

What is RAND?

211 / 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.