Skip to content

Tag: mysql

Left join without using view

I have a table structure similar to this: users | id | name | |—-|——–| | 1 | jane | | 2 | john | client | id | name | user_id | |—-|————|———| | 1 | client 1 |…

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…

I need to optimize this MYSQL query

I have tried NOT EXIST but didn’t get expected result can’t do index since duplicate entries of student_id,status are valid entries,Need to reduce execution time since the table has large number of data. Answer You can try query with JOIN condition: Here the fiddle SQLize.online Sure that your tab…

SQL query for Join statement

I have 3 tables products, pricingGroup and productPricing. I want to show all products even it has no service pricing and set its status/IsActive to false. What query I have now What I want to Get Products Table ProductPricing Table PricingGroup Table Answer You are missing last join clause pricing.PricingGro…

MySQL Not Reading Full Line

I’m using the following SQL Script in my IDE DBeaver, MySQL 8.0.21 Linux (Docker Container). Database is in utf8mb4 / utf8mb4_general_ci encodings. DELIMITER // CREATE OR REPLACE TRIGGER …