Skip to content

SQL – Time difference between rows, conditional

I have a database for logging peeing/pooing time for a puppy. Each row contains a timestamp datetime, and bools pee and poo. I’m trying to add a column for the time since last pee/poo. The verbose version of this column would be: subtract this row’s datetime from datetime of the row with the highe…

Creating a trigger with SELECT Function

Good day everyone, I’m having trouble making my trigger work. As far as the functionality of the body and how it behaves, it does exactly as I intended for it to behave. However, when I start to fire the trigger, it returns an error in which Triggers should not have a SELECT statement from inside the ma…

left join taking too long

I have an issue with query performance and cant find out how to fix it. Both tables have 20k rows Prod_id like indexes but not primary key because table 1 has duplicates with different month, year etc I need to get table like this (table1 * wh = 80k rows): I’m using LEFT JOIN to do this but takes too

SQL query base on three relation with restriction

Customer (CustomerID, FirstName, LastName, Email, PostCode) Salesman (SalesmanNo, empName) Account (AccountNo, SalesmanNo, CustomerID, AccountType) How do I achieve this: Get the name of customer purchase from both Sean and Jean, i believe with the below nested query statement I get the customerID who purchas…