Q:

how to call sub query in if conditional statement on mysql query

I have two tables table1 and table2. i need value of table1 when status=1
    SELECT type, no, 
        CASE WHEN status = '0' THEN 'Vacant'
             WHEN status = '2' THEN 'Repair'
             ELSE (SELECT `field1` FROM `table1` WHERE `field2`=10) AS test END AS addr 
FROM table2

This query outputs error with #1064
how can I get the values in a single MYSQL query?

A:

SELECT type, no, 
    CASE WHEN status = '0' THEN 'Vacant'
         WHEN status = '2' THEN 'Repair'
         WHEN status = '1' (SELECT `field1` FROM `table1` WHERE `field2`=10) END AS addr FROM table2

if you try this code then you won't get error

