In Mysql/MariaDB I like to set the comment of an existing column to a string containing the current date. But I only get SQL syntax errors. I’ve tried so far: Also not working: Of course this works: Is this possible without an external script? Answer demo
Tag: mysql
How do I use SQL to return the first entry in a chronological sort?
I have a table named Dates, let’s just say with two columns for simplicity purposes. One is labeled “date” and that column is of a date data type, and the other one is labeled timestamp and …
Database (1064) SQLSTATE[42000]: Syntax error | Importing using phpmydirectory
So, we use a script called “phpmydirectory”, and at this point it’s pretty outdated. It wasn’t designed to work on PHP 7+ or MySQL 5.7+ but we’re mostly making it work. Part of the script, …
How can I condition the time column?
There is a column representing 24 hours. Data comes in every 15 minutes. For example, at 10:15, the value is entered in the DateTime column of the 10H column. But… The client wants to set the …
How to name a column that is also a function name in SQL?
For example, this doesn’t work, That is because Rank is also a function. I tried to replace Rank with [Rank] but that still doesn’t work. So, what is the solution? Answer You can give it a different name. That is what I would recommend. But absent that, the escape character in MySQL is the backtic…
How can I replace empty value to null with SQL?
Let us say, I want to find the second highest salary. For that I use the following query. However, I want this to return null when the table only contains one entry, and therefore there is no 2nd highest salary. How can I do that? Answer Use your query with aggregation: The aggregate function max() will retur…
How can you assign a value to a variable if mysql does not yield any result?
There are two databases. I am trying to see if email in the first database is also present in the second database. Here’s the code that I’ve tried: The output is: The type for onera and julian is blank because there email is not present in the phpbb_users database. How can I avoid this blank space…
JpaRepository SQL syntax error when trying to save to MySQL Date
I have the following row in my MySQL Table: https://i.stack.imgur.com/u0FC4.png This column is represented as: And it is bound to a Thymeleaf form like so: Now if I insert a date into the MySQL db directly, the date is loaded and set to the correct date on the form: https://i.stack.imgur.com/e35lr.png But eve…
SQL SELF JOIN return null if not exist
Recently, I got a table A like this: I try to SELF JOIN this table by I got this What I expect is when VoucherID doesn’t have any reciprocal account, that record will return null, like this Is there any elegant approach? Thanks all. Answer Why not just use aggregation? You could also do this using left …
Wrong syntax for OVER and PARTITION in MySQL syntax
SELECT Id, Price, CustomerId, ROW_NUMBER() OVER (PARTITION BY CustomerId) FROM Orders; I get the error “Syntax error: Unexpected ‘(‘ (opening parenthesis) Does MySQL not support this? I’m pretty …