Skip to content

Tag: sql

Order of CAST() and COALESCE() matters in MariaDB

I have a strange problem: There is a price in a JSON column in a table and the following statements give different results while they should give the same thing: Just to check I also added a JSON_EXTRACT(item.price_details, “$.shipping.price”) AS shipprice Result: MariaDB version: mariadb Ver 15.1…

Generate random pairs SQL

Suppose we have these two tables. TABLE1: TABLE_2: I want to pair all rows of TABLE_1 with some random columns from TABLE_2 where each pair is gonna have a random amount of distinct rows from TABLE_2 (range 1,2,3) An output could be: Answer did the thing for me.

improve sql query with 2 EXISTS sub queries

I have this query (mysql): It runs multiple times on app start. It takes more than 10 seconds (all of them). I have indexes on: balance_histories table: budget_item_id, family_id (tried also payment_date) budget_lines table: family_id, budget_id, budget_item_id How can I improve the speed? Query or maybe mysq…

Select horses with logical operators [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 9 m…