सही CASE WHEN सिंटैक्स
select
(case
when (first_name = "John") then 'Carol'
when (last_name = "Smith") then 'Doe'
end) RESULT
from demo58;
उदाहरण डेटा
mysql> create table demo58 (id int not null auto_increment primary key, first_name varchar(20), last_name varchar(20));
mysql> insert into demo58(first_name,last_name) values('John','Doe'), ('David','Smith'), ('John','Brown'), ('David','Miller');
परिणाम
+--------+ | RESULT | +--------+ | Carol | (first_name = John) | Doe | (last_name = Smith) | Carol | (first_name = John) | NULL | (कोई शर्त मेल नहीं) +--------+
नियम: पहली TRUE शर्त का परिणाम लौटाया जाता है; ELSE न होने पर NULL मिलता है।