sql >> Base de Datos >  >> RDS >> Mysql

Consulta MySQL usando CASE para SELECCIONAR múltiples columnas

Me gusta IF() función para sentencias simples:

SELECT
    Future.enemy_type,
    IF (Future.enemy_type = 'square', Users.color, '') AS color,
    IF (Future.enemy_type = 'square', Users.user_ID, '') AS ID,
    IF (Future.enemy_type = 'headquarters', Users.username, '') AS username,
    IF (Future.enemy_type = 'headquarters', Users.home_lat, '') AS lat
FROM Future
LEFT JOIN Users
    ON Future.user_ID_affected = Users.user_ID
WHERE
    Future.time > 1539503510  AND
    Future.time <= 1539503512 AND
    Future.user_ID = 10;