PHP | MYSQL Error: Operand should contain 10 column (s) [closed]

0

I'm trying to develop a Query where, it needs to be queried in 6 equal tables if there is any specific value.

Here's my Query:

SELECT (
    CASE WHEN (SELECT * FROM sala1 WHERE aluno = '$AlunoInformado') = 1 THEN END 
    ELSE
        CASE WHEN(SELECT * FROM sala2 WHERE aluno = '$AlunoInformado') = 1 THEN END
        ELSE
            CASE WHEN(SELECT * FROM sala3 WHERE aluno = '$AlunoInformado') = 1 THEN END
            ELSE
                CASE WHEN(SELECT * FROM sala4 WHERE aluno = '$AlunoInformado') = 1 THEN END
                ELSE
                    CASE WHEN(SELECT * FROM sala5 WHERE aluno = '$AlunoInformado') = 1 THEN END
                    ELSE
                        CASE WHEN(SELECT * FROM sala6 WHERE aluno = '$AlunoInformado') = 1 THEN END
                        END
                    END
                END
            END
        END
    END
)entrada FROM $SelectSalas WHERE status = 0

NOTE: $AlunoInformado receives a value that can have on all tables. But when you query, Operand should contain 10 column (s).
What is wrong with the query? Why does not the column show entrada according to the statement before FROM ?

    
asked by anonymous 10.01.2017 / 02:43

1 answer

0
CASE WHEN (SELECT * FROM sala1 WHERE aluno = '$AlunoInformado') = 1 THEN END 
    ELSE

I believe your CASE WHEN is wrong because you are putting the END (the command that terminates CASE) before your ELSE.

And as far as I know, you need to have a result for your "WHEN" ie, WHEN what is after WHEN is true, do x thing, if not (that would be ELSE) do y thing

Thinking the way I said, the code would look like:

SELECT (
   CASE 
      WHEN (SELECT * FROM sala1 WHERE aluno = '$AlunoInformado') = 1 THEN 'sala1'
      ELSE
         CASE 
            WHEN(SELECT * FROM sala2 WHERE aluno = '$AlunoInformado') = 1 THEN 'Sala2'
            ELSE 'Não foi encontrado'
         END
   END
) AS entrada 
FROM $SelectSalas 
WHERE status = 0

And I would indicate you put something more "concrete" in your WHEN, because there you are selecting all the columns of numerous tables, select something x from each table. For example the id of the same, as this makes it easier to validate your condition. Type:

SELECT
   CASE
      WHEN (SELECT tabela_id FROM tabela_x WHERE cod_aluno = '$código') > 1 THEN 'Exite'
      ELSE 'Não existe'
   END

I hope I have helped: D

link

    
10.01.2017 / 13:06