SQL using a union statement

PHOTO EMBED

Fri Sep 29 2023 17:06:07 GMT+0000 (Coordinated Universal Time)

Saved by @jaez #mysql

Table: Employees

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| employee_id | int     |
| name        | varchar |
| salary      | int     |
+-------------+---------+
 If Employee name does not start with M, AND salary is an odd number, give them a bonus of 100%.

         -- select entries with odd  employee id and name not start with M
            select employee_id , salary as bonus 
            from employees 
            where employee_id%2 <>0 and name not like 'M%'
            
        -- join both selection 
            union
            
        -- select remaining entries from table 
            select employee_id , 0 as bonus
            from employees
            where employee_id%2 = 0 or name like 'M%'
            order by employee_id;
content_copyCOPY