0
I have a table in an access database with the following fields:
DATA | SALA | AULA1 | AULA2 | AULA3 | AULA4 | DOCENTE | TURNO
----------------------------------------------------------------------
02/02/2015 | S1 | 1 | 1 | 0 | 0 | JOÃO | MATUTINO
----------------------------------------------------------------------
02/02/2015 | S1 | 0 | 0 | 1 | 1 | JORGE | MATUTINO
----------------------------------------------------------------------
02/02/2015 | S1 | 1 | 1 | 0 | 0 | JOSÉ | MATUTINO
----------------------------------------------------------------------
02/02/2015 | S2 | 1 | 1 | 1 | 0 | MARIA | MATUTINO
I would like to make a consultation that would return the conflicting classes on the day taking into account the day and the room used.
Ex: Day 02/02/2015 Room 01 is being used by the class in the first two hours of class and in the two finals. Note that on the same day 2 (3rd line) there is conflict between 3rd and 1st line (in class 1 and 2 field). I would like to format a query that informs these two conflicts.
Could someone help me?
Sorry for the table format....
Beast, but this command Inner Join not to gather information from more than one table?
– Filipe S. Martins
@Filipes.Martins That’s why I join table 2x itself to find the coincidences.
– Maicon Carraro
I got it, very good guy, I didn’t even imagine I could do it. I noticed that at the exit of the consultation the fields appeared T1. (labellodocampo) and T2. (labellodocampo) of all the fields I entered in the query. You can simplify this?
– Filipe S. Martins
@Filipes.Martins You want to catch what?
– Maicon Carraro
DATA | SALA | AULA1 | AULA2 | AULA3 | AULA4 | DOCENTE | TURNO basically the information that is in the same table. Thank you so much for helping Maicon Carraro
– Filipe S. Martins
@Filipes.Martins In case you have conflict line 1 and 3, which teacher will you show? the 2?
– Maicon Carraro
Exactly, it actually shows all the lines that have conflict. It is as if to show the lines that are duplicated in the fields (date and room and(Aula1 or aula2 or aula3 or aula4)
– Filipe S. Martins
In this case I think it is better to use another solution
EXISTS
, just to confirm you have id in this table?– Maicon Carraro
Yes, I have a code field with automatic numbering
– Filipe S. Martins
@Filipes.Martins I changed the answer with the new solution, a tested
– Maicon Carraro
This last one you sent ended up giving a syntax error in the expression EXISTS...
– Filipe S. Martins
@Filipes.Martins Glue the whole mistake here
– Maicon Carraro
Syntax error in query expression 'EXISTS ( SELECT t2.ID FROM Tblhorario t2 ON t1.ID <> t2.ID AND t1.DATA = t2.DATA AND t1.SALA = t2.SALA WHERE (t1.AULA1 = 1 AND t2.AULA1 = 1) OR (t1.AULA2 = 1 AND t2.AULA2 = 1)
– Filipe S. Martins
One more parenthesis to close
– Maicon Carraro
I closed but the error persists. It will not be some comma that was missing?
– Filipe S. Martins
@Filipes.Martins Perdao, I had forgotten one
ON
inside the exists, arranged in the answer of a check– Maicon Carraro
Top Maicon, I think now it worked blz! I will do more tests.... Thanks for the force.
– Filipe S. Martins
Anything but drip my name again :)
– Maicon Carraro