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

SQL · Theory

IF Statement

← All stacks

Theory

130/439

IF Statement

Inside procedures: IF marks < 40 THEN SET msg = 'fail'; ELSE SET msg = 'pass'; END IF; This is not the IF() function. You need BEGIN … END and DELIMITER when creating the procedure.

Trap — writing IF THEN in a normal query tab. That’s a syntax error. Use IF() or CASE in SELECT.

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

Exam tip

IF THEN is for procedures. SELECT uses IF() / CASE.

IF Statement — sample query

-- IF Statement
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;

IF Statement: create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Short notes

  • DefProcedural IF THEN END IF only in stored programs.
  • RuleSELECT uses IF() or CASE, not IF THEN.
  • TrapIF THEN in a normal query.

Questions

1

Can you use IF THEN in a normal SELECT?

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