I have the following SQL statement running against a MariaDB 10.1.26 with ~2.000 rows with instant results. When I use the following statement with variables for the datetime fields, the execution takes ~5.5 seconds. The more data rows I have, the longer it takes to execute the statement. Seems like the variables change the behaviour of the statement somehow. What’s
Tag: mysql
Execute MySQL’s SQL files using .NET
Whenever I make an update to my database (changes in stored procs, changes in tables, new tables ,etc.), I create a new sql file which I run on client’s computer via TeamViewer. I wanted my …
sql group by – curse and blessing
I have 3 tables for a meal calculation. Now I like to find a meal by ingredient: Which give me a list like: Also I like to find meal by price like: Which give me a list like: Now let me build a query like Which gives me a list like: Because (i.price / i.minamount * r.quanitity) for this meal
WordPress – Save Contact Form 7 fields to the database as separate columns
I am using Contact Form 7 and Contact Form 7 Database Addon – CFDB7 to save values from my form to the database. The database plugin seems to work fine and saves information to the database, I am able …
Avoid N+1 query in large data set
I have a migration which updates existing records with a new attribute value. The model is called ‘MyRecord’. It has millions of records in the database with a new unit_id column of null. I want to …
cannot drop a foreign key in mySQL
It’s a common example between Persons and Orders. I just copied it from Internet as a test. CREATE TABLE Persons ( ID int NOT NULL, LastName varchar(255) NOT NULL, FirstName varchar(…
Select all entries from a table which are older then 3 days
I’ve this table in my database: ————————————————- | id | name | model | inserted_time (timestamp) | ————————————————- When I insert …
How to check if a table contains a specific number of rows?
I have this query: SELECT (COUNT(*) = SUM(status in (3, 5)) ) AS result FROM `match` WHERE round_id = 15 this essentially check if the table match have all the items with a status 3 or 5 for the …
sequelize compare date with date-timestamp
my simple use case is I pass a date and try to compare that with the default createdAt column. and my date is a string like this date = ‘2018-12-12’ The problem here is sequlize not compare only the date. But it does add time 00:00:00 to my date and then compare. So the query sequlize generate is like this.
Is escaping SQL queries like this safe?
I am currently working on a NodeJS backend script that parses incoming HTTP requests to write to and read from a MySQL database for work. I tried to protect it against SQL injections by using a kind of two-layer protection. To write to the database the user needs to provide valid JSON. This is how the JSON’s keys need to