0

hey i am trying to Identify those events which start at the same time as one of the co72010 lectures. and I'm not sure how to go about doing this do i have to do an INNER JOIN or GROUP BY?

events

id          modle kind     dow    tod    duration       room
co12004.L01 co12004 L   Wednesday 11:00     1   cr.SMH
co12004.L02 co12004 L   Monday    17:00     1   cr.B13
co12004.T01 co12004 T   Monday  11:00       2   co.G78+G82
co12004.T02 co12004 T   Tuesday 15:00       2   co.B7
co12004.T03 co12004 T   Tuesday 13:00       2   co.G78+G82
5
  • I don't see anything that has a co72010 in any of the fields. There, that was easy.
    – Siyual
    Sep 5, 2014 at 14:21
  • haha its not the whole list of records... :P
    – Richard
    Sep 5, 2014 at 14:27
  • The point of stating a value into your question is to help others try to find a way to help you. The information is useless unless you show the community the correct values so that one may best understand what you're saying to avoid such comment as @Siyual who in fact is right. Sep 5, 2014 at 14:36
  • In such scenario, it is good to have sample data and the desired result so that one may see what is to be achieved. Sep 5, 2014 at 14:41
  • Which DBMS are you using? Postgres? Oracle? May 27, 2015 at 20:21

3 Answers 3

1

You can use an Exists for this. Perhaps something like this:

Select  E.*
From    Events  E
Where Exists
(
    Select  1
    From    Events  O
    Where   O.dow = E.dow
    And     O.tod = E.tod
    And     O.modle = 'co72010'
)

Alternatively, you can use a Join as well:

Select  E.*
From    Events  E
Join    Events  O   On  O.Dow = E.Dow
                    And O.Tod = E.Tod
Where   O.Modle = 'co72010'
3
  • This seems to be bringing back all but the co7210 result?
    – Richard
    Sep 5, 2014 at 14:47
  • @Richard If you also want the co7210 row, remove the join condition And O.id <> E.id
    – Bohemian
    Sep 5, 2014 at 15:02
  • Ah, wasn't sure if you wanted the co72010 result. I've updated the query.
    – Siyual
    Sep 5, 2014 at 15:02
1
Select  E.*
From    event  E
Where Exists
(
    Select  1
    From    event  O
    Where   O.dow = E.dow
    And     O.tod = E.tod
    And     O.modle = 'co72010'
) and E.modle != 'co72010'

So that it doesn't show the same module, only the ones that are at the same time as co72010, but not it itself ??

0
SELECT a.id, a.modle, a.dow, a.tod, b.id, b.modle, b.dow, b.tod
FROM event a JOIN event b on (a.dow=b.dow AND a.tod=b.tod)
WHERE a.modle = 'co72010' AND b.modle != 'co72010'
1
  • 1
    Welcome to StackOverflow, Providing a little context on why this is the right solution would be helpful. Jan 1, 2016 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.