I need to change a few values on my DB. I forgot to set nullable to the table and it set to 0000-00-00 00:00:00 by default. Now I need to convert that value in NULL. The field type is Datetime. How can I do it? I try with the typical Update table set field = NULL WHERE field = ‘0000-00-00
Tag: mysql
SQL: query repeating rows in join
I’m trying to display all my exercises which are in course A (course_id ‘1’) When I run this query: I get this: It’s worth noting that courses have sessions and in that session there are these exercises. Realistically only exercise_id’s 1 and 4 are linked to course 1. So why are their duplicate rows being returned? Session_id’s 10, 11, 12
Average value for top n records?
i have this SQL Schema: http://sqlfiddle.com/#!9/eb34d In particular these are the relevant columns for this question: ut_id,ob_punti I need to get the average of the TOP n (where n is 4) values of …
Select minute from CURTIME() in a sql query
I have a column with CURTIME() value. I want a query that selects the minute from the column with CURTIME() and copy the minute to another column. Answer You could use the minute function. If you’re just querying it: To save this value to another column:
increment value in mysql after the table has been created
I would like to change the value in the second column to increment and also change the current NULL values to start using that incrementing system that begins at a value other than 1. I do see I can …
SELECT if 2 cells in a row are equal
Tried to show it as simple as possible. I want to SELECT Subject if 2 cells in a row are equal Table Result I need is to select subject C cause username and lastpostername are equal (Sorted DESC by ID, so newest comes first) Answer
@SET (SQL) in PHP
How to state SET @unix_four_weeks_ago = UNIX_TIMESTAMP(curdate()) – 2419200; in php file. SQL PHP The query is all about getting the last 4weeks records. The query was working fine in SQL, but not giving any output when I run php file. Answer As the others already said, multi_query will allow you to run multiple statements in one go. However, this
UPDATE mysql rows
I’m trying to update a lot (close to 500) of rows in mysql database. How can I make it with just 1 query? …and it goes on and on until 500. Answer Use the BETWEEN operator: If not all products with an ID in that range should be updated, you’ll have to use the IN operator and construct the query
Migrating from Oracle to MySQL. VARCHAR2 length defined using bytes. How to port?
I have variable in Oracle procedure declared like this: myMsg VARCHAR2(256 BYTE) How can I port it to mysql? Because this when I try to declare it in MySQL procedure: DECLARE myMsg VARCHAR(256 …
select where time = x or later
I have a table with columns username and timestamp . When a username is entered the current timestamp is as well. I would like to fetch the rows of all the new users from a certain time until now, but the start time varies. Lets make it a timestamp represented by x. I would like to use SQL to select