Relative Content

Tag Archive for sqlmysqlmariadb

use if statement in Trigger to add a value with filtering

issue in the Trigger … You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘delimiter $$
create trigger add_not_before_insert before insert on `customer…’ at line 1

SQL Unique Constraint Across Multiple Database Tables

So a variation of this question has been asked many times; in all of those cases, usually the recommendation is a modifying of the data and the suggested rewrites often make more sense but I can’t figure out a way, with my specific example.

Select lowest time depending price

I am trying to make a query that determines the most favorable, time-dependent prices for a certain period, but also does not exclude objects for which no prices are available for this period.
Since the price periods can be completely flexible, it is not possible to work with larger and smaller queries.
I therefore thought that the smallest difference between start and end should be determined and the smallest price taken (if there are several hits).

Random Assignment of Email Addresses with Special Conditions

Given a series of email addresses, I need to randomly pair them with the condition that if A is to give a gift to B, then B must give a gift to A. If the number of email addresses is odd, the last three must be paired with each other (A with B, B with C, and C with A). I’m implementing this in MySQL with the following code:

Random Pairing of Email Addresses with Special Conditions

Given a series of email addresses, I need to randomly pair them with the condition that if A is to give a gift to B, then B must give a gift to A. If the number of email addresses is odd, the last three must be paired with each other (A with B, B with C, and C with A). I’m implementing this in MySQL with the following code:

MySQL Order subquery by the order that fields from another table come in

I have a custom form builder where admins can create fields and forms separately so that the fields are reusable on multiple forms. The fields can be reordered by admins at any time and have new fields added or existing ones removed, even after submissions have been made. I have 5 tables for this: forms, fields, a form_fields linking table, submissions, and a submission_fields table which is both a linking table and also contains the values of the submitted fields.