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

SQL · Theory

IF()

← All stacks

Theory

126/439

IF()

IF(condition, a, b) is a function: IF(marks >= 40, 'Pass', 'Fail'). CASE is clearer for many branches. IF as a procedure statement (IF THEN END IF) is different — that is flow control inside stored programs.

Trap — mixing IF() function with procedural IF. Trap: nested IF() soup — use CASE.

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

Exam tip

IF(marks >= 40, 'Pass', 'Fail') or CASE WHEN …

IF() — sample query

-- IF()
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(): create two demo rows, then SELECT qty >= 2 ordered. Say which labels come back.

Short notes

  • DefIF(cond, yes, no) per row. Procedural IF is inside procedures.
  • RulePrefer CASE for more than two branches.
  • TrapMixing the two IFs.

Questions

1

Pass/fail column?

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