0
I am trying to develop a Query where, need to be Consulted in 6 equal tables if there is any specific value.
Here is 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
OBS: $AlunoInformado
receives a value you can have in all tables.
But when you query, it presents Operand should contain 10 column(s).
What’s wrong with the query? Why not present the informed column entrada
as instructed before the FROM
?
Isn’t a simple union better? http://answall.com/questions/163399/como-buscar-um-mesmo-termo-em-4-tabelas-different - and it would not be the case that the tables are organized so as to have a relation pupil-room instead of several tables of room?
– Bacco
@Bacco Not for this case, because I need to separate by rooms and by day of scheduling. As I am not very good at SQL, this was the simplest and fastest way it worked. UNION is not returning results, I do not know the reason, but does not return.
– Hugo Christian
If you post a small sample data collection to http://SQLFiddle.com, I can try to help. Without the data and table structure, it gets more complicated. As to separate the rooms, if you have a "room" column with the number, just use a WHERE to choose the desired room.
– Bacco
Can you post the table structure you are using? Only the Structure, does not need to specify the data, but the times that this error returned to me, was because the table I was using in FROM had less or more columns than the amount returned in the function SELECT
– Diéfani Favareto Piovezan