frgdgdfg dfgdgdgd
frgdgdfg dfgdgdgd

Reputation: 57

Accessing enum from objects

Hey guys am new to mysql development..I hve wrote some code like

 CREATE TABLE CUSTOMERS(
   ID   INT              NOT NULL,
   NAME VARCHAR (20)     NOT NULL,
   AGE  INT              NOT NULL,
   ADDRESS  CHAR (25) ,
   SALARY   DECIMAL (18, 2), 
   PRIMARY KEY (ID)
);


INSERT INTO  CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY)  
VALUES (1,'aff',2,3,5);



set @a := CASE WHEN NAME = 'aff' THEN 5 ELSE 3 END;

when i run the varibale @a it throws error like Schema Creation Failed: Unknown column 'NAME' in 'field list':

Can anyone help me ..An sql fiddle example would be realy apreciated ..Thanx

Upvotes: 0

Views: 24

Answers (1)

Barmar
Barmar

Reputation: 781098

To get something from a table, you have to use a SELECT query:

SET @a := (SELECT CASE WHEN name = 'aff' THEN 5 ELSE 3 END
            FROM CUSTOMERS
            LIMIT 1);

DEMO

When using a SELECT as an expression, it must only return 1 row, that's why I added the LIMIT 1 clause.

Upvotes: 1

Related Questions