Skip to content
Advertisement

select rows with events related with another events in the same query column

I need to select rows with EventTypeID = 19 which does not have related EventtypeID = 21 LoggedOn exactly 4 minutes earlier for the same EmployeeID. Here’s the query bellow and some raw output:

What I need to achieve is:

TerminalID column value is always 3 in that scenario and it’s not related with any query condition, but must be in the output for syntax requirement in the futher processing.

Advertisement

Answer

The bad practice to join tables using conditions in WHERE. The block WHERE need to use to filter first of all. And aliases help to make code shorter.

Try to use the following:

If there don’t need any conditions you can use CROSS JOIN.

I got your result using your data:

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement